Project

redcache

0.0
No commit activity in last 3 years
No release in over 3 years
A wrapper for Redis, for caching and encryption with Fernet
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 0.5
~> 0.0
~> 10.0
~> 3.0

Runtime

~> 2.1
~> 1.10
~> 3.1
 Project Readme

Redcache

A gem for caching data in Redis.

This gem caches data from slow services in Redis, but ensures that the cache is up to date.

Should the cache be cold, the result is cached. Should the cache be warm but considered stale, the cache is still used, but updated subsequently via a threaded request, thus not blocking the original request.

This gem is also able to encrypt the cached results with Fernet if required.

Installation

Add this line to your application's Gemfile:

gem 'redcache'

And then execute:

$ bundle

Or install it yourself as:

$ gem install redcache

Usage

Redcache.configure do |c|
  c.redis = $redis
  c.secret = <some_long_hash>
  c.encrypt = true
end

value = Redcache.cache "unique_cache_key" do
  call_to_slow_service
end

arguments can also be passed into Redcache is needed for when your stale refreshes are run:

value = Redcache.cache "unique_cache_key", api, id do |api, id|
  api.call_to_slow_service id
end

Configuration

Several configuration options are available to use that defined the behaviour of redcache.

:redis Connection to redis
:secret If encrypting, what secret should be used. See [Fernet](https://github.com/fernet/fernet-rb) README for more information
:encrypt Should cached data be encrypted (boolean)
:skip_cache Should the cache be skipped. Useful in test environments (boolean)
:logged Standard logger object to use for logging
:log_prefix String to prefix to l2met compatible log lines
:cache_time Time (in seconds) to cache data for before expiring
:stale_time Time (in seconds) before cached data should be considered stale

Testing

Specs to come ;)

Contributing

  1. Fork it ( https://github.com/[my-github-username]/redcache/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