Re: [Cheetahtemplate-discuss] About cheetah cache
Brought to you by:
rtyler,
tavis_rudd
From: Silvio Di S. <sdi...@sd...> - 2006-05-02 02:02:20
|
Yes, but only functions inside that file, which are the ones I want them to execute. I don't think cheetah supports that. Anyway, here's a class I wrote, I hope it's useful to someone. It is designed to work with small files, as it prefers to just rebuild the cache in case it gets corrupted rather than locking the file in each request. I think that's more practical with small files where you don't usually expect many connections to use the same cache (I have one cache file per user), but locking should be implemented for larger files. Greetings class Cache(dict): def __init__(self): """This should be overriden by subclass. self.path is required, self.logger recommended""" pass def __getitem__(self,key): try: if key in self.cache['__Outdated']: raise Exception() return self.cache[key] except: return False def __setitem__(self,key,value): self.cache[key]=3Dvalue if key in self.cache['__Outdated']: self.cache['__Outdated'].remove(key) def load(self): import cPickle as pickle self._open('rb') try: self.cache=3Dpickle.load(self.fh) self._close() except: #file broken, restart cache. If there's a logger defined, an even happier function try: self.logger.log.warning('Cache '+self.path+' was forcedly restarted.') except: pass self._close() self.create() self.load() def save(self): import cPickle as pickle self._open('wb') pickle.dump(self.cache,self.fh,1) self._close() def outDate(self,key): self.cache['__Outdated'].append(key) def _open(self,mode): if not self.path: raise Exception('A path must be set for cache') self.fh=3Dfile(self.path,mode) def _close(self): self.fh.close() def create(self): self.cache=3D{'__Outdated':[]} self.save() def __repr__(self): return repr(self.cache) On 5/1/06, Shannon -jj Behrens <jj...@gm...> wrote: > Weird, looking at that code, can the user really choose to execute > *any* function by putting it in the URL? > > By the way, Mike is right. If you have multiple Python processes, > which is pretty normal in mod_python, it's hard to get them to share a > cache unless you cache to disk or use memcache, etc. I forget, does > Cheetah support that? I personally have never needed to use the whole > cache system. :-/ > > -jj > > On 4/28/06, Silvio Di Stefano <sdi...@sd...> wrote: > > Hey people, cheetah newbie says hi. > > I've been playing with the cache and couldn't make it work at all. > > I tryed the three variants, and it just reloads the page every time. > > Is there something I should consider? > > I'm using mod_python with this handler I wrote > > def handler(req): > > req.content_type=3D'text/html' > > #Analyze URL > > uri=3Dreq.uri.split('/') > > function=3Duri[2] > > params=3Duri[3:] > > #Call function if exists > > if(True): > > globals()['TEMPLATE_PATH']=3D\ > > req.get_options()['root_path']+'/api/templates/' > > sys.path+=3D(TEMPLATE_PATH,) > > EF.setReq(req) > > EF.startSession() > > from admin.client import client > > globals()['client']=3Dclient() > > req.write(params and eval(function)(params) or eval(fun= ction)()) > > # except: return apache.HTTP_NOT_FOUND > > return apache.OK > > > > Any ideas? > > -- > > Silvio Di Stefano > > > > > > ------------------------------------------------------- > > Using Tomcat but need to do more? Need to support web services, securit= y? > > Get stuff done quickly with pre-integrated technology to make your job = easier > > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geron= imo > > http://sel.as-us.falkag.net/sel?cmdlnk&kid=120709&bid&3057&dat=121642 > > _______________________________________________ > > Cheetahtemplate-discuss mailing list > > Che...@li... > > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss > > > -- Silvio Di Stefano |