Simple LRU Cache, implemented with ets.
The package can be installed as:
- Add lru_cache to your list of dependencies in
mix.exs:
defdepsdo[{:lru_cache,"~> 0.1.0"}]end- Ensure lru_cache is started before your application:
defapplicationdo[applications: [:lru_cache]]endTypically you want to start the cache from a supervisor:
worker(LruCache,[:my_cache,10])Or starting it manually:
LruCache.start_link(:my_cache,10)The resulting process and ets table will be registered under this alias. Now you can use the cache as follows:
LruCache.put(:my_cache,"id","value")LruCache.get(:my_cache,"id")LruCache.get(:my_cache,"id",touch=false)LruCache.update(:my_cache,"id","new_value",touch=false)LruCache.delete(:my_cache,"id")