Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arago/lru_cache
ETS-based fix-sized LRU cache for elixir
https://github.com/arago/lru_cache
Last synced: about 1 month ago
JSON representation
ETS-based fix-sized LRU cache for elixir
- Host: GitHub
- URL: https://github.com/arago/lru_cache
- Owner: arago
- License: other
- Created: 2015-11-05T16:24:48.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-01-16T17:34:51.000Z (almost 3 years ago)
- Last Synced: 2024-10-30T16:56:24.623Z (about 1 month ago)
- Language: Elixir
- Homepage:
- Size: 11.7 KB
- Stars: 36
- Watchers: 12
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Simple LRU Cache, implemented with ets. (Caching)
- fucking-awesome-elixir - lru_cache - Simple LRU Cache, implemented with ets. (Caching)
- awesome-elixir - lru_cache - Simple LRU Cache, implemented with ets. (Caching)
README
# LruCache
Simple LRU Cache, implemented with `ets`.
## Installation
The package can be installed as:
1. Add lru_cache to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:lru_cache, "~> 0.1.0"}]
end
```2. Ensure lru_cache is started before your application:
```elixir
def application do
[applications: [:lru_cache]]
end
```## Using
Typically you want to start the cache from a supervisor:
```elixir
worker(LruCache, [:my_cache, 10])
```Or starting it manually:
```elixir
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:
```elixir
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")
```