i did not catch the fish how i can store and expire queries without the need to specify an object id. If i only store single objects there is everything ok, but in my case i want to store complete Queries, such as hole paginated pages in memcached.
When i store a query through cache_fu it will stored im memcached with information such as
set [projectname]-[environment]:[Classname]:[my cache_key]
If i expire_cache for a given Object it appends an additional object.id to the cache_key such as
delete [projectname]-[environment]:[Classname]:[Object.id]:[my cache_key]
So i have to add the Object.id by my self at get_cached like
def self.cached_get_pagination(category_id, itemorder, page)
get_cache("#{category_id.to_s}:page_#{itemorder}_#{page}") do
Item.get_pagination(category_id, itemorder, page)
end
end
But on one page i didn't have an Object.id because it is displaying all Channel with one depended Item, so i can't set an Object.id for this case.
def self.cached_get_pagination_latest(itemorder, page)
get_cache("page_#{itemorder}_#{page}") do
Item.get_pagination(itemorder, page)
end
end
set [projectname]-[environment]:[Classname]:page_[my item order]_[page number]
So, if one Channel is created or saved i want to clear my cache, but in this case cache_fu sets automatically the id of the given Object and my request to memcached looks like
set [projectname]-[environment]:[Classname]:[Object.id]:page_[my item order]_[page number]
and the cache didn't get expired.
How i'm able to set a sort of id undependent cache?
Regards,
Matthias
> Any help is much appreciated. Caching pagination (I'm using
> will_paginate) seems to be a common roadblock that I haven't seen a
> good blog post, screencast, etc. for yet.
I usually do something like this:
Or, even better, just cache the fragments and have `expire_pages`
expire a certain # of cached fragments.
- Chris
> One question...why aren't don't the methods cached_page and fetch_page
> have "self." before them? Wouldn't I want to call
> Product.cached_page(1) or are you recommending I call it in some other
> way.
You're right, my mistake: http://pastie.caboo.se/157431
- Chris