|
252 | 252 | (testing "TTL cache does not contain a value that was removed from underlying cache." |
253 | 253 | (let [underlying-cache (lru-cache-factory {} :threshold 1) |
254 | 254 | C (ttl-cache-factory underlying-cache :ttl 360000)] |
255 | | - (is (not (-> C (assoc :a 1) (assoc :b 2) (has? :a))))))) |
| 255 | + (is (not (-> C (assoc :a 1) (assoc :b 2) (has? :a)))))) |
| 256 | + (testing "TTL cache propagates hits to the underlying cache's recency tracking." |
| 257 | + (let [underlying-cache (lru-cache-factory {} :threshold 2) |
| 258 | + C (-> (ttl-cache-factory underlying-cache :ttl 360000) |
| 259 | + (assoc :a 1) |
| 260 | + (assoc :b 2)) |
| 261 | + C' (-> C (hit :a) (hit :a) (assoc :c 3))] |
| 262 | + (is (has? C' :a) |
| 263 | + ":a was hit twice and should not have been evicted in favor of :b")))) |
256 | 264 |
|
257 | 265 | (deftest test-lu-cache-ilookup |
258 | 266 | (testing "that the LUCache can lookup via keywords" |
@@ -529,3 +537,13 @@ N non-resident HIR block |
529 | 537 | (let [c (fifo-cache-factory {:a 1 :b 2} :threshold 2)] |
530 | 538 | (is (= #{:a :c} (set (-> c (evict :b) (miss :c 42) (.q))))) |
531 | 539 | (is (= #{:c :d} (set (-> c (evict :b) (miss :c 42) (miss :d 43) (.q))))))) |
| 540 | + |
| 541 | +(deftest propagation-to-composed-cache70 |
| 542 | + (testing "hits on a composed cache (TTL wrapping LRU) propagate to the wrapped cache's recency tracking" |
| 543 | + (let [c-cache (-> {:a 10 :b 20} |
| 544 | + (lru-cache-factory :threshold 3) |
| 545 | + (ttl-cache-factory :ttl 30000)) |
| 546 | + c-cache2 (miss c-cache :c 30) |
| 547 | + c-cache3 (-> c-cache2 (hit :b) (hit :b) (hit :b)) |
| 548 | + c-cache4 (miss c-cache3 :d 40)] |
| 549 | + (is (has? c-cache4 :b) ":b was hit 3 times and should not have been evicted in favor of :a or :c")))) |
0 commit comments