cache clearing from within a Pylons controller?

已查看 57 次
跳至第一个未读帖子

Isaac Csandl

未读,
2008年9月23日 11:34:092008/9/23
收件人 Mako Templates for Python
Hi,

I'm thinking of the common situation where a controller is updating an
object: it should be possible to manually pluck out the relevant defs
and/or <%page>'s to clear the now-invalid data. Anybody know how?

--i

Michael Bayer

未读,
2008年9月23日 18:53:262008/9/23
收件人 mako-d...@googlegroups.com

its something I've been considering adding an API for. Currently it
would look something like (this is against latest trunk):

template = lookup.get_template("/path/to/my/template.mako")
cache = template.module._template_cache
cache._get_container(keyname, type="file").clear_value()

"keyname" is the name of the def ("body" for the whole page) or
whatever key you use for cache_key.

Isaac Csandl

未读,
2008年9月23日 21:19:252008/9/23
收件人 Mako Templates for Python


On Sep 23, 5:53 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
> its something I've been considering adding an API for.   Currently it  
> would look something like (this is against latest trunk):
>

Consider it requested! I had a feeling you were already on top of it.

Thanks!

Michael Bayer

未读,
2008年9月24日 22:46:512008/9/24
收件人 mako-d...@googlegroups.com

On Sep 23, 2008, at 9:19 PM, Isaac Csandl wrote:

>
>
>
> On Sep 23, 5:53 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
>> its something I've been considering adding an API for. Currently it
>> would look something like (this is against latest trunk):
>>
>
> Consider it requested! I had a feeling you were already on top of it.

maybe if you want to add a trac ticket to remind me. not sure when I
can get to this.

Michael Bayer

未读,
2008年9月27日 10:56:382008/9/27
收件人 mako-d...@googlegroups.com
OK, check out this feature in http://www.makotemplates.org/trac/changeset/405
. You'd have to get at your Pylons-configured TemplateLookup to
get at the Template.

Isaac Csandl

未读,
2008年9月29日 15:30:332008/9/29
收件人 Mako Templates for Python


On Sep 27, 9:56 am, Michael Bayer <mike...@zzzcomputing.com> wrote:
> OK, check out this feature inhttp://www.makotemplates.org/trac/changeset/405
>   .   You'd have to get at your Pylons-configured TemplateLookup to  
> get at the Template.

Wow, thanks! I'll take it for a spin today and let you know. :D

--i


Isaac Csandl

未读,
2008年9月30日 10:41:112008/9/30
收件人 Mako Templates for Python
It works! Thanks again.

Isaac Csandl

未读,
2008年9月30日 11:42:572008/9/30
收件人 Mako Templates for Python


On Sep 30, 9:41 am, Isaac Csandl <nerk...@gmail.com> wrote:
> On Sep 29, 2:30 pm, Isaac Csandl <nerk...@gmail.com> wrote:
>
> > On Sep 27, 9:56 am, Michael Bayer <mike...@zzzcomputing.com> wrote:
>
> > > OK, check out this feature inhttp://www.makotemplates.org/trac/changeset/405
> > >   .   You'd have to get at your Pylons-configured TemplateLookup to  
> > > get at the Template.
> It works! Thanks again.

Update:

mytemplate.cache.invalidate('somekey') works, but invalidate_def
appears not to. There's no error message, but the def shows the same
data until the cache expires. (I'm testing using FF with WebDev
extension set to disable cache, to rule out browser caching)

For what I need, this will do, so no pressure to fix it on my
account. :)

--i

Michael Bayer

未读,
2008年10月1日 20:21:112008/10/1
收件人 mako-d...@googlegroups.com

On Sep 30, 2008, at 11:42 AM, Isaac Csandl wrote:

>
>
>
> On Sep 30, 9:41 am, Isaac Csandl <nerk...@gmail.com> wrote:
>> On Sep 29, 2:30 pm, Isaac Csandl <nerk...@gmail.com> wrote:
>>
>>> On Sep 27, 9:56 am, Michael Bayer <mike...@zzzcomputing.com> wrote:
>>
>>>> OK, check out this feature inhttp://www.makotemplates.org/trac/changeset/405
>>>> . You'd have to get at your Pylons-configured TemplateLookup to
>>>> get at the Template.
>> It works! Thanks again.
>
> Update:
>
> mytemplate.cache.invalidate('somekey') works, but invalidate_def
> appears not to. There's no error message, but the def shows the same
> data until the cache expires. (I'm testing using FF with WebDev
> extension set to disable cache, to rule out browser caching)
>

does your <%def> use cache_key ? the feature isn't looking at custom
cache_keys right now.

Isaac Csandl

未读,
2008年10月3日 10:46:492008/10/3
收件人 Mako Templates for Python
Yeah, that must be why.

Isaac Csandl

未读,
2008年10月3日 18:49:512008/10/3
收件人 Mako Templates for Python
On further consideration, I may have misunderstood how it was intended
to be used. What is working here is actually clearing the value of a
cached def (with cache_key) by using
mytemplate.cache.invalidate('key'). I was probably assuming
invalidate_def would simply clear *all* cached values for the def,
regardless of cache_key (or lack thereof). So... it seems there is
nothing to fix, but it may be worthwhile to make the docs on this
extra clear (e.g., "invalidate_def does nothing to defs with a
cache_key") so somebody else doesn't make the same mistake.

happy friday!

回复全部
回复作者
转发
0 个新帖子