Friday, May 14, 2010

[Rails] Re: New to cacheing

Hi,

Jeremy Woertink wrote:
> Ok, So, I'm a bad developer and have never used any sort of cacheing
> before. I decided it's time I step up and I threw in some memcached
> magic. I'm still pretty new to all this, so I'm confused on how some
> things work. I've watched the railscast on cacheing, and gone through
> many tutorials.
>
> So, the problem I'm having is that I have this page being cached, and
> it's not updating the page when I do any sort of CRUD action on the
> model primarily used on this page.
>
> Here is what I have
>
> class SiteController < ApplicationController
> caches_action :index
>
> def index
> #this in my home page
> end
> en
>
> class ListingsController < SiteController
> #This is the page being cached
> def index
> @listings = Listing.all
> end
> end
>
> class ListingSweeper < ActionController::Caching::Sweeper
> observe Listing
>
> def after_save(listing)
> expire_cache(listing)
> end
>
> def after_update(listing)
> expire_cache(listing)
> end
>
> def after_destroy(listing)
> expire_cache(listing)
> end
>
> def expire_cache(listing)
> expire_action root_path
> expire_action listings_path
> end
>
> end
>


It seems to me that you miss to specify the cache sweeper in the
controller.
In your case, try to add this:

class SiteController < ApplicationController
caches_action :index
cache_sweeper :listing_sweeper

Regards,

.Viet Trung.
--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate