Skip to content

majioa/redisize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redisize

The gem allows to use asynchonous way to cache or just store in redis or any other cache mechanism. For asynchronous caching the Resque or Sidekiq adapters can be used, for synchronous - inline.

Installation

Add this line to your application's Gemfile:

gem 'redisize'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install redisize

Usage

Initialization

Usually adapter can'be defined automatically of presently installed gems. Curretly are supported sidekiq and resque gems to ansyncronous caching (redisizing). If no such gems are installed, the synchronous inline adapter is used. You can redefine manually an adapter as follows:

Redisize.adapter_kind = :inline

Other values are :resque, and :sidekiq. And then to use the gem just define in the target object:

include(Redisize)

In Rails

To use the cache feature with Rails (and ActiveRecord) you have just to wrap a method accessing DB either a record or a relation to a block like this. So to redisize a record value as a json use the follwing:

redisize_json(attrs) do
   # <JSON generation code>
   # generate_json(attrs, options)
end

to drop a JSON value use:

deredisize_json(attrs)

to redisize an SQL:

redisize_sql do
   relation.as_json(context)
end

to redisize an record instance use:

redisize_model(slug, by_key: :slug) do
   self.joins(:slug).where(slugs: {text: slug}).first
end

Next calls to the block will return a cached value. Updating the record will drop cache for sql or record itself.

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/majioa/redisize. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Redisize project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

Make json record cacheable to redis via various adapters like Resque, Sidekiq, etc

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published