Skip to content

Commit 8df0e2b

Browse files
[sonic-cfggen] store jinja2 cache in log level db. (#5646)
This PR makes two changes: - Store Jinja2 cache in LOGLEVEL DB instead of STATE DB - Store bytecode cache encoded in base64 Tested with the following command: "redis-dump -d 3 -k JINJA2_CACHE" Signed-off-by: Stepan Blyschak <[email protected]>
1 parent d8363a9 commit 8df0e2b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import jinja2
22

3+
from base64 import b64encode, b64decode
4+
35
class RedisBytecodeCache(jinja2.BytecodeCache):
46
""" A bytecode cache for jinja2 template that stores bytecode in Redis """
57

@@ -8,19 +10,20 @@ class RedisBytecodeCache(jinja2.BytecodeCache):
810
def __init__(self, client):
911
self._client = client
1012
try:
11-
self._client.connect(self._client.STATE_DB, retry_on=False)
13+
self._client.connect(self._client.LOGLEVEL_DB, retry_on=False)
1214
except Exception:
1315
self._client = None
1416

1517
def load_bytecode(self, bucket):
1618
if self._client is None:
1719
return
18-
code = self._client.get(self._client.STATE_DB, self.REDIS_HASH, bucket.key)
20+
code = self._client.get(self._client.LOGLEVEL_DB, self.REDIS_HASH, bucket.key)
1921
if code is not None:
20-
bucket.bytecode_from_string(code)
22+
bucket.bytecode_from_string(b64decode(code))
2123

2224
def dump_bytecode(self, bucket):
2325
if self._client is None:
2426
return
25-
self._client.set(self._client.STATE_DB, self.REDIS_HASH, bucket.key, bucket.bytecode_to_string())
27+
self._client.set(self._client.LOGLEVEL_DB, self.REDIS_HASH,
28+
bucket.key, b64encode(bucket.bytecode_to_string()))
2629

0 commit comments

Comments
 (0)