Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

How to use it with cache sweeper? #14

Closed
phuongnd08 opened this issue Nov 23, 2012 · 5 comments
Closed

How to use it with cache sweeper? #14

phuongnd08 opened this issue Nov 23, 2012 · 5 comments

Comments

@phuongnd08
Copy link

If I want to invalidate a cache when a model is created, how would I do it?

@dhh
Copy link
Member

dhh commented Nov 23, 2012

Call #touch on whatever you've made that cache depend on. See key-based expiration.

@dhh dhh closed this as completed Nov 23, 2012
@phuongnd08
Copy link
Author

Okay, I guess my case is a little special:
So I make a cache like this:

- cache 'testimonials' do
  = render 'testimonials', :testimonials => Testimonial.approved

We implemented a sweeper to make a call to expire_fragment('testimonial') when a testimonial is changed. But as far as I tried, expire_fragment doesn't work (because the cache key 'testimonial/'?)

@dhh
Copy link
Member

dhh commented Nov 24, 2012

Cache digests is not intended to work with manual expiration using a sweeper. Only key-based expiration.

On Nov 24, 2012, at 9:24, phuongnd08 notifications@github.com wrote:

Okay, I guess my case is a little special:
So I make a cache like this:

cache 'testimonials' do = render 'testimonials', :testimonials => Testimonial.approved
Inside the testimonials template, we fetch all approved testimonials using: Testimonial.approved and render each of them. We implemented a sweeper to make a call to expire_fragment('testimonial') when a testimonial is changed. But as far as I tried, expire_fragment doesn't work (because the cache key 'testimonial/'?)


Reply to this email directly or view it on GitHub.

@phuongnd08
Copy link
Author

Are you saying expire_fragment work without cache_digests but won't work with cache_digests?

@dhh
Copy link
Member

dhh commented Nov 25, 2012

Correct. They are not designed to work together. Cache digests are only intended to work together with key-based expiration where you never need to manually expire and know the whole cache key.

There's a pull request available for turning off the digest on a per-call basis pending, though.

On Nov 25, 2012, at 7:05, phuongnd08 notifications@github.com wrote:

Are you saying expire_fragment work without cache_digests but won't work with cache_digests?


Reply to this email directly or view it on GitHub.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants