ObjectCache
Simple object caching for ruby.
Installation
Add this line to your application's Gemfile:
gem 'object_cache'
And then execute:
$ bundle
Or install it yourself as:
$ gem install object_cache
Usage
in an initializer define ObjectCache.source "path_to_yml_file" and optional ObjectCache.ttl 5.minutes (or anything else)
From that moment on you can use ObjectCache.key to access the object you defined as "key".
The yml file looks like this:
key:
name: ClassName
id: 4
another_key:
name: ClassName
id: 5
it assumes ClassName has a method find which can be used by ClassName.find([4,5]) and returns the correct objects. (usually ActiveRecord, but can be used for mongoid objects, etc.)
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request