Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Public Member Functions | List of all members
jinja2.bccache.BytecodeCache Class Reference
Inheritance diagram for jinja2.bccache.BytecodeCache:
Inheritance graph
[legend]

Public Member Functions

None load_bytecode (self, Bucket bucket)
 
None dump_bytecode (self, Bucket bucket)
 
None clear (self)
 
str get_cache_key (self, str name, t.Optional[t.Union[str]] filename=None)
 
str get_source_checksum (self, str source)
 
Bucket get_bucket (self, "Environment" environment, str name, t.Optional[str] filename, str source)
 
None set_bucket (self, Bucket bucket)
 

Detailed Description

To implement your own bytecode cache you have to subclass this class
and override :meth:`load_bytecode` and :meth:`dump_bytecode`.  Both of
these methods are passed a :class:`~jinja2.bccache.Bucket`.

A very basic bytecode cache that saves the bytecode on the file system::

    from os import path

    class MyCache(BytecodeCache):

        def __init__(self, directory):
            self.directory = directory

        def load_bytecode(self, bucket):
            filename = path.join(self.directory, bucket.key)
            if path.exists(filename):
                with open(filename, 'rb') as f:
                    bucket.load_bytecode(f)

        def dump_bytecode(self, bucket):
            filename = path.join(self.directory, bucket.key)
            with open(filename, 'wb') as f:
                bucket.write_bytecode(f)

A more advanced version of a filesystem based bytecode cache is part of
Jinja.

Member Function Documentation

◆ clear()

None jinja2.bccache.BytecodeCache.clear (   self)
Clears the cache.  This method is not used by Jinja but should be
implemented to allow applications to clear the bytecode cache used
by a particular environment.

Reimplemented in jinja2.bccache.FileSystemBytecodeCache.

◆ dump_bytecode()

None jinja2.bccache.BytecodeCache.dump_bytecode (   self,
Bucket  bucket 
)
Subclasses have to override this method to write the bytecode
from a bucket back to the cache.  If it unable to do so it must not
fail silently but raise an exception.

Reimplemented in jinja2.bccache.FileSystemBytecodeCache, and jinja2.bccache.MemcachedBytecodeCache.

◆ get_bucket()

Bucket jinja2.bccache.BytecodeCache.get_bucket (   self,
"Environment"  environment,
str  name,
t.Optional[str]  filename,
str  source 
)
Return a cache bucket for the given template.  All arguments are
mandatory but filename may be `None`.

◆ get_cache_key()

str jinja2.bccache.BytecodeCache.get_cache_key (   self,
str  name,
t.Optional[t.Union[str]]   filename = None 
)
Returns the unique hash key for this template name.

◆ get_source_checksum()

str jinja2.bccache.BytecodeCache.get_source_checksum (   self,
str  source 
)
Returns a checksum for the source.

◆ load_bytecode()

None jinja2.bccache.BytecodeCache.load_bytecode (   self,
Bucket  bucket 
)
Subclasses have to override this method to load bytecode into a
bucket.  If they are not able to find code in the cache for the
bucket, it must not do anything.

Reimplemented in jinja2.bccache.FileSystemBytecodeCache, and jinja2.bccache.MemcachedBytecodeCache.

◆ set_bucket()

None jinja2.bccache.BytecodeCache.set_bucket (   self,
Bucket  bucket 
)
Put the bucket into the cache.

The documentation for this class was generated from the following file: