示例#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
示例#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
示例#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
示例#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
示例#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"
示例#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"
示例#7
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
示例#8
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
示例#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 = 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
示例#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 = 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