Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

47 lines (33 sloc) 1.59 KB

Gem Version

This is a gem that provides Ruby objects with the capability of object caching. This gem is framework-agnostic, so it can be used in all the types of Ruby applications.


Use gem:

gem install object_cacheable

Use bundle:
In Gemfile, write:

gem 'object_cacheable'

In your application, write:

require 'object_cacheable'

In your application, there must be a directory called conf or config (either will work) that contains a file called cache_configs.yml.

Object that wants to be cached must include Cacheable,

class Person
    include Cacheable

and implement the method:

def self.fetch(attributes,args)
    # Your code to do the real object retrieval here
    # It can be database call, webservices call or complex object builder
    # The first argument attributes is an array of attribute names that we want to retrieve the object by
    # The second argument args is an array of values of the attributes
    # for example Person.fetch(['first_name', 'last_name'], ['Linh', 'Chau'])
    # But the combinations of attributes must be able to identify a unique object

When a Class includes Cacheable and defines the method "fetch", it's instances will become cacheable, and all the cache operations will be handled by the module Cacheable.

Testing bundle exec ruby -Ilib test/models/cacheable_test.rb

Jump to Line
Something went wrong with that request. Please try again.