Zero-footprint Ruby In-Memory Thread-Safe Cache
Branch: master
Clone or download
Latest commit 6a6dc91 Feb 12, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib #32 remove_by Jan 30, 2019
test #32 remove_by Jan 30, 2019
.0pdd.yml #1 skeleton Nov 1, 2018
.gitignore #25 Zache::Fake Dec 21, 2018
.pdd #1 skeleton Nov 1, 2018
.rubocop.yml rubocop Feb 6, 2019
.rultor.yml eo badge Nov 7, 2018
.travis.yml travis Feb 5, 2019
Gemfile ver 2.3 Feb 6, 2019
README.md link Feb 12, 2019
Rakefile rdoc Nov 3, 2018
appveyor.yml appveyor 2.5 Feb 6, 2019
zache.gemspec #27 rubocop up Jan 8, 2019

README.md

EO principles respected here DevOps By Rultor.com We recommend RubyMine

Build Status Build status Gem Version Maintainability Yard Docs

It's a simple Ruby gem for in-memory cache. Read this blog post to understand what Zache is for.

First, install it:

$ gem install zache

Then, use it like this

require 'zache'
zache = Zache.new
# Expires in 5 minutes
v = zache.get(:count, lifetime: 5 * 60) { expensive() }

By default Zache is thread-safe. It locks the entire cache on each get call. You turn that off by using sync argument:

zache = Zache.new(sync: false)
v = zache.get(:count) { expensive() }

You may use "dirty" mode, which will return you an expired value, while calculation is waiting. Say, you have something in the cache, but it's expired. Then, you call get with a long running block. The thread waits, while another one calls get again. That second thread won't wait, but will receive what's left in the cache. This is a very convenient mode for situations when you don't really care about data accuracy, but performance is an issue.

The entire API is documented here (there are many other convenient methods).

That's it.

How to contribute

Read these guidelines. Make sure you build is green before you contribute your pull request. You will need to have Ruby 2.3+ and Bundler installed. Then:

$ bundle update
$ rake

If it's clean and you don't see any error messages, submit your pull request.

License

(The MIT License)

Copyright (c) 2018 Yegor Bugayenko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.