Plugins - Memcache fragments with time expiry

StarAdd to favorites

About

memcache_fragments is a very simple plugin (10 lines of code!) that

  1. makes rails fragment caching play nice with robot coop’s memcache-client by wrapping its get/set methods with read/write methods that rails expects.
  2. makes it easy to do time based fragment expiry using this syntax:
  <% cache 'my/cache/key', :expire => 10.minutes do %>
        ...
  <% end %>

Installing and using memcache_fragments

You’ll first need the memcache-client gem from robot coop

  $ sdo gem install memcache-client

Now install the plugin

  $ script/plugin install memcache_fragments

Alternatively, you can use the gem

  $ sudo gem install memcache_fragments

  # in environment.rb
  require 'memcache_fragments'

Setting up the fragment cache

See the docs from memcache-client, but I found placing this in your environment.rb (or specific environment) to be the easiest:

  CACHE = MemCache.new :c_threshold => 10_000,:compression => true,:debug => false,:namespace => 'mycachespace',:readonly => false,:urlencode => false
  CACHE.servers = 'localhost:11211'

  config.action_controller.session_store = :mem_cache_store
  config.action_controller.fragment_cache_store = CACHE, {}
  ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.merge!({ 'cache' => CACHE })

Yan Pritzker

http://skwpspace.com/2006/08/19/rails-fragment-cache-with-memcached-client-and-time-based-expire-option/

svn://rubyforge.org/var/svn/mcache-fragment

PublicDomain

  • Currently 4.4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Misc. Enhancements

Tags

cachecachingfragment_cachememcachedview

Comments

Add a comment
What comes next? 'Monday Tuesday Wednesday ?????'
renuka 26 Apr 2007

hello, i have install this plugin and i have got this error so can anyone help me

MemCache Error: No connection to server Fragment read: my/cache/key (0.00270)

ActionView::TemplateError (can't convert true into String) on line #4 of app/views/tag/_tagcloud.rhtml: 1: <!-- START POPULAR TAGS --> 2: <div> 3: <h2>Popular Tags</h2> 4: <% cache 'my/cache/key', :expire => 2.minutes do %> 5: <% tagcloud @tags, %w(nube1 nube2 nube3 nube4 nube5) do |name, cssclass| %> 6: <%= linkto name, {:action => :tagdetail, :controller => 'tag', :id => name}, :class => cssclass %> 7: <% end %>

pls give me reply as soon as possible

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?