You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
puredanger edited this page May 22, 2012
·
11 revisions
FIFO cache
A First-In-First-Out cache is one that uses queuing logic for its backing store, expunging the elements at the front of the queue when a predetermined limit is exceeded.
General use
To create a core.cache FIFOCache instance you can do the following:
The cache instance C is initialized with the seed map {:a 1, :b 2} and a queue limit of 3, For your own purposes 2 is probably too small, but it's fine for the purpose of illustration. Since the queue limit was set to 3 you might expect that adding another element to the cache would insert a 3rd element, and indeed that is the case:
(assoc C :c42)
;=> {:a 1, :b 2, :c 3}
However, adding one more element should evict one element, and indeed it does:
(-> C (assoc:c3, :z42))
;=> {:z 42, :c 3, :b 2}
Like all of the implementations in core.cache, FIFOCache instances operate like regular maps and are immutable.