Uploaded image for project: 'core.cache'
  1. CCACHE-46

TTL cache's has? doesn't check existence of value in the underlying cache

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Completed
    • Labels:
      None
    • Patch:
      Code and Test

      Description

      (extracted from the comments thread of the CCACHE-15)

      In case TTL cache is wrapped around other cache capable of evicting values based on some logic (e. g., LRU cache) TTL's has? would return true until TTL period of the given key is expired even if the underlying cache doesn't contain the value.

      user> (require '[clojure.core.cache :as cache])
      user> (let [C (-> {}
                        (cache/lru-cache-factory :threshold 1) ; base cache that contains one element at most
                        (cache/ttl-cache-factory :ttl 360000) ; TTL cache with big TTL to ensure key is not expired
                        )
                  C2 (if (cache/has? C :c)
                       (cache/hit C :c)
                       (cache/miss C :c 42))
                  C3 (if (cache/has? C2 :d)
                       (cache/hit C2 :d)
                       (cache/miss C2 :d 42))]
              [(cache/has? C3 :c)
               (cache/lookup C3 :c)])
      [true nil] ; TTL cache reports it contains the given key but value is actually not present
      

        Attachments

          Activity

            People

            • Assignee:
              seancorfield Sean Corfield
              Reporter:
              gsnewmark Ivan Kryvoruchko
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: