def remove(self): cache.init(self.path) cache.set('foo', 'bar', 'baz') cache.remove('foo') cache.remove('invalid') assert cache.get('foo', 'bar') == None assert cache.get('invalid', 'bla') == None
def content(self): """Returns the processed content. This one of the core functions of acrylamid: it compiles incrementally the filter chain using a tree representation and saves final output or intermediates to cache, so we can rapidly re-compile the whole content. The cache is rather dumb: Acrylamid can not determine wether it differs only in a single character. Thus, to minimize the overhead the cache object is zlib-compressed.""" # previous value pv = None # this is our cache filename path = self.cachefilename # remove *all* intermediates when entry has been modified if cache.getmtime(path) > 0.0 and self.modified: cache.remove(path) if self.hasproperty('copy'): res = self.resources if res: # use ascii record separator between paths, ignore empty list cache.set(path, 'resources', '\x1e'.join(res)) # growing dependencies of the filter chain deps = [] for fxs in self.filters.iter(context=self.context): # extend dependencies deps.extend(fxs) # key where we save this filter chain key = hash(*deps) try: rv = cache.get(path, key) if rv is None: res = self.source if pv is None else pv for f in fxs: res = f.transform(res, self, *f.args) pv = cache.set(path, key, res) else: pv = rv except (IndexError, AttributeError): # jinja2 will ignore these Exceptions, better to catch them before traceback.print_exc(file=sys.stdout) return pv