caching - 带有上限和 TTL 的 Clojure 缓存

标签 caching clojure

我正在使用 clojure.core.memoize (使用 clojure.core.cache )。我想用 TTL cache但也希望对总缓存大小设置上限(因为我可以为 FIFO 缓存提供)。

我知道有各种各样的缓存组合了队列、TTL 等。我不一定想要那种奇特的东西,只是一种限制集合大小的简单方法?

最佳答案

clojure.core.memoize中的所有内存功能似乎采用了一个可选的基本缓存,可用于组合不同的缓存策略:

(require '[clojure.core [memoize :as memo] [cache :as cache]])
(def memoized-identity
  (memo/fifo
    identity
    (cache/ttl-cache-factory {} :ttl 5000)
    :fifo/threshold 32))

core.cachewiki entry on composability想要查询更多的信息。

关于caching - 带有上限和 TTL 的 Clojure 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25995397/

相关文章:

Spring @Cacheable 默认 TTL

python - 如何让 functools.lru_cache 返回新实例?

dictionary - 同时将多个元素Conj成一个向量

java - 使用函数式风格合并两个数组

clojure - 使用lazy-seq无需删除堆栈: is it possible to combine laziness with tail recursion?

php - Laravel 尝试将缓存文件存储在根文件夹中

caching - 为什么Netflix在memcached上写了Evcache而不是在Redis上

php - Symfony2 Redis Validator,字符串而不是 ClassMetadata

clojure - 构建目录树

clojure - 为什么记录不是函数?