Skip to content

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

License

Notifications You must be signed in to change notification settings

kostya/memory_cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •