Navigation Menu

Skip to content

dwaynemac/cache_version

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CacheVersion

Rails gem to generate cache versions for your model It allows to have several versions with keys to identify them.

Install

Gem

soon...

Plugin

script/plugin install git://github.com/dwaynemac/cache_version.git

Usage

Two methods are provided to the model.

version(key,consider_updated_at)

returns a string representing version for this model under key. if consider_update_key is true version has the following format: cache_key/key:key_version else version has the following format: class_nameModel_id/key:key_version

increment_version(key,consider_updated_at)

increments by one version for given key and returns it. consider_updated_at is only needed if you’ll use returned value.

Example

in product.rb

class Product
  cache_version

  ...
end

in reseller.rb

class Reseller
  after_save :update_product

  def update_product
    self.product.increment_version('resellers')
  end
end

in products/show.html.erb

<h1>Buyers</h1>
<%- cache(product.version('buyers',false)) do -%>
 ...
<%- end -%>

<h1>Resellers</h1>
<%- cache(product.version('resellers')) do -%>
 ...
<%- end -%>

Version

Internally CacheVersion uses module Version wich is also made available for the application. This module provides

Version.increment(key,by)

Version.decrement(key,by)

Version.read(key)

Version.set(key,value)

About

Easy cache versioning for models. Allows multiple versions with keys to identify them

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages