Michael Wright wrote:
> hello,
> 
> I am new to programming and am trying to create a clear_cache method.
> This method is invoked when a submit button is pressed on a partial.
> 

You *might* want to do this via a method call to the model after the 
update/save is completed.

> 
> def clear_cache
>     Dir.chdir('../../../../../')
>     system('rake _0.7.3_ tmp:cache:clear')
>     redirect_to 'http://127.0.0.1:3000/admin'
> end
> 

tmp:cache:clear is an awfully heavy-handed way to clear the cache.  If 
you smart-code your cache keys, a simple call to Rails.cache.delete from 
within the model selectively dump cache fragments, whether that 
'fragment' is a little bit of HTML or a whole page, just depends on your 
cache key.

Your controllers can use Rails.cache.exist?(fragment_name) to avoid the 
DB hit:

Your views can contain code like:
<% cache(fragment_name) do %>
   regular erb or haml or whatever
<% end %>

and the models expire their own fragments via code using 
Rails.cache.delete(fragment_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