-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4e5622
commit 374e1ed
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import cache | ||
|
||
import jinja2 | ||
|
||
|
||
class KeystoreCache(jinja2.BytecodeCache): | ||
def __init__(self): | ||
super().__init__() | ||
self._cache_connection = None | ||
def load_bytecode(self, bucket): | ||
cache_key = self._template_key(bucket.key) | ||
self._ensure_connection() | ||
cached_bytecode = self._cache_connection.get(cache_key) | ||
if cached_bytecode: | ||
bucket.bytecode_from_string(bytes(cached_bytecode, "utf-8")) | ||
def dump_bytecode(self, bucket): | ||
cache_key = self._template_key(bucket.key) | ||
bytecode = str(bucket.bytecode_to_string()) | ||
self._ensure_connection() | ||
self._cache_connection.set(cache_key, bytecode) | ||
def _ensure_connection(self): | ||
if not self._cache_connection: | ||
self._cache_connection = cache.Cache() | ||
def _template_key(self, template_name): | ||
return "jinja2-template-%s" % template_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters