Clojure vector cache

I am looking for a cache that behaves like a vector. I used core.cache , but these are maps. I just need a simple eviction method. I understand that I can just create my own using the CacheProtocol protocol, but I wanted to know if something like this exists, or if there is a reason, this is a bad idea.

+4
source share
1 answer

If all you need is a vector similar to the cache interface, then it is likely that the index cache for the values ​​will meet your needs. I guess a little about your specific problem, although it seems likely that using numbers as keys to your cache will fill in many use cases , because vectors are conceptually very similar to number cards with values:

 user> (def C (cache/fifo-cache-factory {0 1 1 0})) user> (get C 0) 1 

if this is not enough, you can see the current contents of your cache as such a vector:

 user> (vec (map #(get C % nil) (range 11))) [1 0 nil nil nil nil nil nil nil nil nil] 

In most cases, the likelihood that using numbers as indices will do the job for many people.

+2
source

Source: https://habr.com/ru/post/1436018/


All Articles