I had the same problem last month.
Digging around the source code of pylons.decorators.cache.py,
There is a method called 'create_cache_key' that you can call to invalidate
directly.
Below is how I invalidate beaker_cache:
from pylons import cache, request
from pylons.decorators.cache import create_cache_key
class CacheHandler(object):
@classmethod
def expire_controller_cache(cls, func):
'''
Usage: CacheHandler.expire_controller_cache(getattr(controller_instance,
action_name))
'''
key_dict = request.GET.mixed()
namespace, key = create_cache_key(func, key_dict)
cache.get_cache(namespace).remove(key)
# Example Controller
class SomeController(BaseController):
def index(self):
pass
# How to use it
some_controller = SomeController()
CacheHandler.expire_controller_cache(getattr(some_controller, 'index'))
- Didip -
On Fri, May 14, 2010 at 8:45 AM, Brian O'Connor <[email protected]> wrote:
> Hi Doug,
>
> A quick look through the beaker docs yielded this:
> http://beaker.groovie.org/caching.html#id3
>
> Hope that helps!
> Brian
>
> On 5/14/10, writes_on <[email protected]> wrote:
> >
> > Hi all,
> >
> > Thanks to some help from Brian, I'm using the @beaker_cache decorator
> from:
> >
> > from pylons.decorators.cache import beaker_cache
> >
> > in my pylons application. This is working well to cache some large SA
> query
> > objects and expire them after awhile. This brings me to my next question:
> > how do manually expire/reset a cached item that's been saved using this
> > syntax? For instance, suppose I have some code that looks like this:
> >
> > @beaker_cache(expire=300, type='memory', cache_response=False)
> > def _expensiveQuery(self, id):
> > return self.model.expensive.query(id)
> >
> > Which will cache the results of the query for 5 minutes in memory. And
> let's
> > say some other controller action updates the tables that affect
> > _expensiveQuery(). How do I clear the cache results for this object so
> the
> > next time this controller action is called the _expensiveQuery() will
> re-run
> > the actual query and get the new table values rather than return the
> cached
> > copy?
> >
> > Thanks!
> > Doug
> >
> > --
> > View this message in context:
> >
> http://pylons-discuss.1595796.n2.nabble.com/beaker-cache-how-to-clear-a-cached-element-tp5051429p5051429.html
> > Sent from the pylons-discuss mailing list archive at Nabble.com.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "pylons-discuss" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<pylons-discuss%[email protected]>
> .
> > For more options, visit this group at
> > http://groups.google.com/group/pylons-discuss?hl=en.
> >
> >
>
> --
> Sent from my mobile device
>
> Brian O'Connor
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<pylons-discuss%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en.