Sha256: 9f2a932fe0c1d497dcc392fcea1b2589a25125fbbbd389b586ffa5a5bac1670b

Contents?: true

Size: 1.65 KB

Versions: 6

Compression:

Stored size: 1.65 KB

Contents

cacheable
=========

cacheable is a simple cache implementation based on activerecord, it is
extracted from [rails-bestpractices.com][1].

it supports activerecord >= 3.0.0

Introduction
------------

Here is a blog post to introduce simple_cacheable gem, <http://rails-bestpractices.com/blog/posts/24-simple_cacheable>

Usage
-----

    class User < ActiveRecord::Base
      include Cacheable

      has_many :posts
      has_one :account

      model_cache do
        with_key                          # User.find_cached(1)
        with_attribute :login             # User.find_cached_by_login('flyerhzm')
        with_method :last_post            # user.cached_last_post
        with_association :posts, :account # user.cached_posts, user.cached_account
      end

      def last_post
        posts.last
      end
    end

    class Account < ActiveRecord::Base
      belongs_to :user
    end

    class Post < ActiveRecord::Base
      include Cacheable

      belongs_to :user
      has_many :comments, :as => :commentable

      model_cache do
        with_key                          # post.find_cached(1)
        with_association :user, :comments # post.cached_user, post.cached_comments
      end
    end

    class Comment < ActiveRecord::Base
      include Cacheable

      belongs_to :commentable, :polymorphic => true

      model_cache do
        with_association :commentable  # comment.cached_commentable
      end
    end

Install
-------

add the following code to your Gemfile

    gem "simple_cacheable", :require => "cacheable"


Copyright © 2011 Richard Huang (flyerhzm@gmail.com), released under the MIT license


[1]:https://github.com/flyerhzm/rails-bestpractices.com

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
simple_cacheable-1.1.5 README.md
simple_cacheable-1.1.4 README.md
simple_cacheable-1.1.3 README.md
simple_cacheable-1.1.2 README.md
simple_cacheable-1.1.1 README.md
simple_cacheable-1.1.0 README.md