cachex elixir 强大的缓存框架

cachex 是一个强大的elixir cache 库,提供了事务,fallback,以及过期等基本能力

包含的特性

  • TTL
  • 最大大小限制
  • pre、post 执行hooks
  • 事务以及row 锁
  • 异步写操作
  • 分布式
  • 同步本地文件系统
  • streaming cache
  • 批量写
  • 用户命令调用
  • 统计信息

参考使用

  • 分布式模式
    对于测试需要配置sname 比如iex --sname a@localhost -S mix
 
defmodule CacheApp do
  def init do
    Cachex.start_link(:my_cache, [nodes: [:a@localhost,:b@localhost]])
  end
 
  def set(key, value) do
    Cachex.put(:my_cache, key, value)
  end
 
  def get(key) do
    Cachex.get(:my_cache, key)
  end
end

注意: 每个节点需要先进行init 操作,每个节点的cache 进程都需要启动

说明

elixir 周边的一些框架以及工具因为利用了erlang 天然的分布式特性,使用起来比较方便

参考资料

https://github.com/whitfin/cachex
https://hexdocs.pm/cachex/getting-started.html

posted on 2024-01-16 09:50  荣锋亮  阅读(19)  评论(0编辑  收藏  举报

导航