sieve_cache.cr

SIEVE Cache for Crystal lang

sieve_cache

SIEVE Cache for Crystal lang

API DOC

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      sieve_cache:
        github: lost22git/sieve_cache.cr
    
  2. 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

  1. Fork it (https://github.com/lost22git/sieve_cache.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • lost - creator and maintainer
Repository

sieve_cache.cr

Owner
Statistic
  • 2
  • 0
  • 0
  • 0
  • 1
  • 3 months ago
  • May 25, 2024
License

MIT License

Links
Synced at

Sun, 15 Sep 2024 15:51:14 GMT

Languages