Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    def clear(self):

        cache.init(self.path)
        cache.set('foo', 'bar', 'baz')
        cache.set('spam', 'bar', 'baz')

        cache.clear()
        assert cache.get('foo', 'bar') == None
        assert cache.get('spam', 'bar') == None
Exemplo n.º 3
0
    def clear(self):

        cache.init(self.path)
        cache.set('foo', 'bar', 'baz')
        cache.set('spam', 'bar', 'baz')

        cache.clear()
        assert cache.get('foo', 'bar') == None
        assert cache.get('spam', 'bar') == None
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    def persistence(self):

        cache.init(self.path)
        cache.set('foo', 'bar', "Hello World!")
        cache.set('foo', 'baz', "spam")
        assert cache.get('foo', 'bar') == "Hello World!"
        assert cache.get('foo', 'baz') == "spam"

        cache.shutdown()
        cache.init(self.path)
        assert cache.get('foo', 'bar') == "Hello World!"
        assert cache.get('foo', 'baz') == "spam"
Exemplo n.º 6
0
    def persistence(self):

        cache.init(self.path)
        cache.set('foo', 'bar', "Hello World!")
        cache.set('foo', 'baz', "spam")
        assert cache.get('foo', 'bar') == "Hello World!"
        assert cache.get('foo', 'baz') == "spam"

        cache.shutdown()
        cache.init(self.path)
        assert cache.get('foo', 'bar') == "Hello World!"
        assert cache.get('foo', 'baz') == "spam"
Exemplo n.º 7
0
 def modified(self):
     changed = self.lastmodified > cache.getmtime(self.cachefilename)
     # skip resource check if changed is true
     if not changed and self.hasproperty('copy'):
         # using ascii record separator between paths, ignore empty list
         pv = cache.get(self.cachefilename, 'resources')
         if pv:
             return self.resources != pv.split('\x1e')
         else:
             # flag as modified if resource list is not empty and cache is
             return (not self.resources) == False
     return changed
Exemplo n.º 8
0
 def modified(self):
     changed = self.lastmodified > cache.getmtime(self.cachefilename)
     # skip resource check if changed is true
     if not changed and self.hasproperty('copy'):
         # using ascii record separator between paths, ignore empty list
         pv = cache.get(self.cachefilename, 'resources')
         if pv:
             return self.resources != pv.split('\x1e')
         else:
             # flag as modified if resource list is not empty and cache is
             return (not self.resources) == False
     return changed
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
    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 = join(cache.cache_dir, self.md5)

        # 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 = md5(*deps)

            try:
                rv = cache.get(path, key, mtime=self.lastmodified)
                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)
                    self.has_changed = True
                else:
                    pv = rv
            except (IndexError, AttributeError):
                # jinja2 will ignore these Exceptions, better to catch them before
                traceback.print_exc(file=sys.stdout)

        return pv
Exemplo n.º 12
0
    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 = join(cache.cache_dir, self.md5)

        # 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 = md5(*deps)

            try:
                rv = cache.get(path, key, mtime=self.lastmodified)
                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)
                    self.has_changed = True
                else:
                    pv = rv
            except (IndexError, AttributeError):
                # jinja2 will ignore these Exceptions, better to catch them before
                traceback.print_exc(file=sys.stdout)

        return pv