sieve_cache
SIEVE Cache for Crystal lang
Installation
-
Add the dependency to your
shard.yml
:dependencies: sieve_cache: github: lost22git/sieve_cache.cr
-
Run
shards install
Usage
require "sieve_cache"
cache = SieveCache::Cache(String,String).new(2)
cache["koo"] = "car"
cache["foo"] = "bar"
cache["zoo"] = "baz"
p! cache.cap # => 2
p! cache.len # => 2
p! cache["koo"]? # => nil, koo is evicted
p! cache["foo"]? # => "bar"
p! cache["zoo"]? # => "baz"
begin
cache["koo"]
rescue ex : KeyError
# ...
end
cache.del("foo")
p! cache.has?("foo") # => false
p! cache.get("foo", "bar") # => "bar"
p! cache.has?("foo") # => false
p! cache.get_or_set("foo", "bar") # => "bar"
p! cache.has?("foo") # => true
cache.clear
p! cache.len # => 0
Development
Run tests
just test
Run bench
just bench bench/bench1.cr
Contributing
- Fork it (https://github.com/lost22git/sieve_cache.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- lost - creator and maintainer