Skip to main content

storage: don't store raw keys in the SQLite database

ID
0e99c6b
date
2026-11-07 14:24:50+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
1e1c897
message
storage: don't store raw keys in the SQLite database

I thought this might be useful for debugging, but I haven't actually
used it, and it significantly increases the storage cost.
changed files
1 file, 7 additions, 7 deletions

Changed files

src/funkycache/storage.py (9728 → 9672)

diff --git a/src/funkycache/storage.py b/src/funkycache/storage.py
index d8b5aab..383ef82 100644
--- a/src/funkycache/storage.py
+++ b/src/funkycache/storage.py
@@ -187,7 +187,7 @@ class SQLiteCacheStorage[V](TypedCacheStorage[V]):
             #   - enc_key is the JSON-serialised, hashed key
             #   - raw_key is the JSON-serialised key (for debugging)
             #   - value is the JSON-serialised value
-            "funkycache_entries": "CREATE TABLE funkycache_entries(enc_key PRIMARY KEY, raw_key, value)",  # noqa: E501
+            "funkycache_entries": "CREATE TABLE funkycache_entries(enc_key PRIMARY KEY, value)",  # noqa: E501
         }
 
         # Get a fingerprint for the current table definitions
@@ -252,7 +252,7 @@ class SQLiteCacheStorage[V](TypedCacheStorage[V]):
         """
         self.close()
 
-    def _encode_key(self, key: Mapping[str, Any]) -> tuple[str, str]:
+    def _encode_key(self, key: Mapping[str, Any]) -> str:
         """
         Encode a mapping as a string key.
 
@@ -261,7 +261,7 @@ class SQLiteCacheStorage[V](TypedCacheStorage[V]):
         Using fixed-size keys improves SQLite performance.
         """
         json_key = json.dumps(key, sort_keys=True, default=str)
-        return json_key, _hash(json_key)
+        return _hash(json_key)
 
     def _set_str(self, key: Mapping[str, Any], value: str) -> None:
         """
@@ -270,12 +270,12 @@ class SQLiteCacheStorage[V](TypedCacheStorage[V]):
         Throws an exception if you overwrite an existing key with
         a different value.
         """
-        json_key, enc_key = self._encode_key(key)
+        enc_key = self._encode_key(key)
 
         try:
             self.con.execute(
-                "INSERT INTO funkycache_entries VALUES (?,?,?)",
-                (enc_key, json_key, value),
+                "INSERT INTO funkycache_entries VALUES (?,?)",
+                (enc_key, value),
             )
             self.con.commit()
         except sqlite3.IntegrityError as err:
@@ -293,7 +293,7 @@ class SQLiteCacheStorage[V](TypedCacheStorage[V]):
 
         Throws a KeyError if you look up a key which isn't in the cache.
         """
-        _, enc_key = self._encode_key(key)
+        enc_key = self._encode_key(key)
 
         res = self.con.execute(
             "SELECT value FROM funkycache_entries WHERE enc_key=?", (enc_key,)