memory_cache

Version, currently 0.34 versions

github.com/kostya/memory_cache

Super simple in memory key-value storage with expires for Crystal.

30 stars
3 dependents
License: MIT

Nothing has been indexed for 0.3 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.

Installation

# Add this to your shard.yml
dependencies:
  memory_cache:
    github: kostya/memory_cache
    version: ~> 0.3

Then run:

shards install

shard.yml

No shard.yml has been indexed for 0.3. You can read it on the repository.

Dependencies

Unknown: the shard.yml for this version has not been read yet.

README

This README is the one indexed from the repository at its latest ref, not from the tag for this version.

MemoryCache

CI

Super simple in memory key-value storage with expires for Crystal.

Installation

Add this to your application's shard.yml:

dependencies:
  memory_cache:
    github: kostya/memory_cache

Usage

require "memory_cache"

cache = MemoryCache(String, Int32).new

cache.write("bla", 1)
p cache.read("bla") # => 1

cache.fetch("haha") { 2 }
p cache.read("haha") # => 2

cache.write("expired1", 1, expires_in: 1.second)
p cache.read("expired1") # => 1
sleep 1
p cache.read("expired1") # => nil

p cache.fetch("expired1", expires_in: 1.second) { 2 } # => 2
p cache.fetch("expired1", expires_in: 1.second) { 3 } # => 2
sleep 1
p cache.fetch("expired1", expires_in: 1.second) { 3 } # => 3