Justin Britten wrote:
> I'm having some difficulty finding a way to expire the cache after
> executing an asynchronous BackgroundRB task.  From a Rails controller I
> fire off an async worker which will handle importing of data from a file
> and, when completed, the fragment cache of a page needs to be expired.
> I've tried ...
> 
> 1.  Simply calling expire_action from within the BackgroundRB worker.
> However, it appears that BackgroundRB doesn't have access to
> ActionController.
> 
> 2.  Using sweepers/observers on the model object being changed by the
> BackgroundRB worker.  The BackgroundRB worker will do some stuff with
> the model object, the observer will catch this, and the sweeper will
> handle expiring the cache.  However, the sweeper complains that the
> record passed to the after_whatever callback methods is nil.  Without
> this model object I can't expire the correct cache.
> 
> Using Rails 2.1 and the absolute latest BackgroundRB from github.
> 
> Any suggestions?
> 
> Cheers,
> Justin

Have you tried using Rails.cache.delete(cache_path) from the model?

The sweepers weren't fine-grained enough for my fragment caching, and I 
ended up just taking control of the cache expiration (for my app, a 
single model may have, oh, 8 different fragments cached, and it may 
appear in cache fragments of any number of other models -- polymorphic 
relationships are cool, but have their downside -- so depending on what 
changed, a model knows what caches it should expire of its own, and if 
fragments of models it has a relationship with should expire also - 
i.e., my name field changed and that other model's cache shows my name).
-- 
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to