## Installation
Add this line to your application's Gemfile:
gem 'sequel_acts_as_cacheable'
Or install it yourself as:
$ gem install sequel_acts_as_cacheable
## Usage
Allows you to setup model level caching for your Sequel ORM models.
This gem is designed to work in concert with the dalli gem, but you can really use any caching adapter that implements the following methods:
-set key, value, time_to_live=nil
-get key
-delete key
Example using dalli:
CACHE = Dalli::Client.new 'localhost:11211'
Sequel::Model.plugin :acts_as_cacheable, :cache => CACHE, :time_to_live => 3600
Once a model has been setup with this plugin, it will
-automatically cache primary key lookups. For example Account[3] or Report[55].
-automatically break cache whenever you call save on the model.
## Additional methods provided for manual control of caching
-cache!
-cached?
-uncache!
-invalidate_cache!
## Additional hooks provided
This plugin adds the before_cache hook so you can have more control over what gets cached into your model.
Example usage:
class Thing < Sequel::Model
plugin :acts_as_cacheable, :cache => CACHE, :time_to_live => 3600, :logger => logger #logger is optional
def before_cache
heavy_computation
end
def heavy_computation
@heavy_computation ||= ...
end
end
In this example, the next time a Thing object is retrieved from cache, it will automatically have the result of the heavy computation.
## Contributing
1. Fork it
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 new Pull Request
or.......
If you have any suggestions for how to make this better or extend it, please email me at MishaAConway@gmail.com and I
will be happy to consider suggestions.
Project
sequel_acts_as_cacheable
Memcaching for sequel models.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
Development
Dependencies
Project Readme