Domanda

I'm working on a search feature that when typing something make an ajax call to get the results. I wanna caches the search action with search keywords in memory_cache, so i make it like this:

# caches_action with GET parameters

caches_action :search_posts, :cache_path => Proc.new { |c| c.params }

My question is how can i expire the action with parameters too? Is there another way to make my feature works?

È stato utile?

Soluzione

You have several options to expire this kind of cache.

First one (simpler one) is to add :expires_in option to your caches_action statement - for example:

caches_action :search_posts, :cache_path => Proc.new { |c| c.params }, :expires_in => 16.hours.to_i

This will automatically expire this key after some time.

Or you can expire this cache using expire_action method from controller. It should be like:

expire_action :action => 'posts', :q => 'query'

given you have requested this page with one parameter q=query .

You can read more in the official documentation .

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top