Re: [Cheetahtemplate-discuss] [PATCH] Add method Template.checkFileMtime() to set whether to use i
Brought to you by:
rtyler,
tavis_rudd
From: R. T. B. <ty...@sl...> - 2009-03-27 17:50:09
|
Can you provide a test case to chreck this feature properly before I roll it in? -----Original Message----- From: Jean-Baptiste Quenot <jb...@ca...> Sent: Friday, March 27, 2009 6:33 To: che...@li... Subject: [Cheetahtemplate-discuss] [PATCH] Add method Template.checkFileMtime() to set whether to use included file modification time in cache entry key Here's a patch to avoid hitting the filesystem to get the file modification time everytime a #include directive is processed in a Cheetah template. I use it like this in the initialization of my web application: import Cheetah.Template Cheetah.Template.checkFileMtime(False) src/Template.py | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Template.py b/src/Template.py index f4e0c59..6112cb6 100644 --- a/src/Template.py +++ b/src/Template.py @@ -71,6 +71,12 @@ from Cheetah.Utils.WebInputMixin import _Converter, _lookup, NonNumericInputErro from Cheetah.Unspecified import Unspecified +# Whether to use include file modification time in cache entry key +__checkFileMtime = True + +def checkFileMtime(check): + globals()['__checkFileMtime'] = check + class Error(Exception): pass class PreprocessError(Error): pass @@ -690,8 +696,10 @@ class Template(Servlet): fileHash = None if file: - fileHash = str(hash(file))+str(os.path.getmtime(file)) - + fileHash = str(hash(file)) + if globals()['__checkFileMtime']: + fileHash += str(os.path.getmtime(file)) + try: # @@TR: find some way to create a cacheHash that is consistent # between process restarts. It would allow for caching the -- Jean-Baptiste Quenot http://jbq.caraldi.com/ ------------------------------------------------------------------------------ _______________________________________________ Cheetahtemplate-discuss mailing list Che...@li... https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss |