• Home
  • Raw
  • Download

Lines Matching +full:cache +full:- +full:name

1 """The optional bytecode cache system. This is useful if you have very
26 def get(self, key: str) -> bytes:
29 def set(self, key: str, value: bytes, timeout: t.Optional[int] = None) -> None:
34 # Magic bytes to identify Jinja bytecode cache files. Contains the
46 and initialized by the bytecode cache and passed to the loading functions.
48 The buckets get an internal checksum from the cache assigned and use this
49 to automatically reject outdated cache material. Individual bytecode
50 cache subclasses don't have to care about cache invalidation.
53 def __init__(self, environment: "Environment", key: str, checksum: str) -> None:
59 def reset(self) -> None:
63 def load_bytecode(self, f: t.BinaryIO) -> None:
82 def write_bytecode(self, f: t.IO[bytes]) -> None:
90 def bytecode_from_string(self, string: bytes) -> None:
94 def bytecode_to_string(self) -> bytes:
102 """To implement your own bytecode cache you have to subclass this class
106 A very basic bytecode cache that saves the bytecode on the file system::
126 A more advanced version of a filesystem based bytecode cache is part of
130 def load_bytecode(self, bucket: Bucket) -> None:
132 bucket. If they are not able to find code in the cache for the
137 def dump_bytecode(self, bucket: Bucket) -> None:
139 from a bucket back to the cache. If it unable to do so it must not
144 def clear(self) -> None:
145 """Clears the cache. This method is not used by Jinja but should be
146 implemented to allow applications to clear the bytecode cache used
151 self, name: str, filename: t.Optional[t.Union[str]] = None
152 ) -> str:
153 """Returns the unique hash key for this template name."""
154 hash = sha1(name.encode("utf-8"))
161 def get_source_checksum(self, source: str) -> str:
163 return sha1(source.encode("utf-8")).hexdigest()
168 name: str,
171 ) -> Bucket:
172 """Return a cache bucket for the given template. All arguments are
175 key = self.get_cache_key(name, filename)
181 def set_bucket(self, bucket: Bucket) -> None:
182 """Put the bucket into the cache."""
187 """A bytecode cache that stores bytecode on the filesystem. It accepts
188 two arguments: The directory where the cache items are stored and a
191 If no directory is specified a default cache directory is selected. On
196 same directory. The default pattern is ``'__jinja2_%s.cache'``. ``%s``
197 is replaced with the cache key.
199 >>> bcc = FileSystemBytecodeCache('/tmp/jinja_cache', '%s.cache')
201 This bytecode cache supports clearing of the cache using the clear method.
205 self, directory: t.Optional[str] = None, pattern: str = "__jinja2_%s.cache"
206 ) -> None:
212 def _get_default_cache_dir(self) -> str:
213 def _unsafe_dir() -> "te.NoReturn":
223 if os.name == "nt":
228 dirname = f"_jinja2-cache-{os.getuid()}"
259 def _get_cache_filename(self, bucket: Bucket) -> str:
262 def load_bytecode(self, bucket: Bucket) -> None:
277 def dump_bytecode(self, bucket: Bucket) -> None:
278 # Write to a temporary file, then rename to the real name after
281 name = self._get_cache_filename(bucket)
284 dir=os.path.dirname(name),
285 prefix=os.path.basename(name),
290 def remove_silent() -> None:
292 os.remove(f.name)
306 os.replace(f.name, name)
315 def clear(self) -> None:
316 # imported lazily here because google app-engine doesn't support
330 """This class implements a bytecode cache that uses a memcache cache for
337 - `cachelib <https://github.com/pallets/cachelib>`_
338 - `python-memcached <https://pypi.org/project/python-memcached/>`_
340 (Unfortunately the django cache interface is not compatible because it
342 the underlying cache client to the bytecode cache which is available
343 as `django.core.cache.cache._client`.)
351 Stores the bytecode in the cache. `value` is a string and
354 provided it's an integer with the number of seconds the cache
359 Returns the value for the cache key. If the item does not
360 exist in the cache the return value must be `None`.
363 is added before the actual cache key and the timeout for the bytecode in
364 the cache system. We recommend a high (or no) timeout.
366 This bytecode cache does not support clearing of used items in the cache.
367 The clear method is a no-operation function.
386 def load_bytecode(self, bucket: Bucket) -> None:
395 def dump_bytecode(self, bucket: Bucket) -> None: