Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A gem for object-level caching. Framework-agnostic. Can be used anywhere.
Ruby
tree: d68fa7ad3a

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test/models
Gemfile
README.md
object_cacheable.gemspec

README.md

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.

Object that wants to be cached must include Cacheable,

class Person
    include Cacheable
end

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
end

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

Something went wrong with that request. Please try again.