Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

refactor: Remove unnecessary CACHE_KEY_SECRET and HMAC hashing

LearningCircuite473d10bb80c
diff --git a/src/local_deep_research/memory_cache/app_integration.py b/src/local_deep_research/memory_cache/app_integration.py
index 3fbf415782..d5945da34f 100644
--- a/src/local_deep_research/memory_cache/app_integration.py
+++ b/src/local_deep_research/memory_cache/app_integration.py
@@ -32,8 +32,5 @@ def setup_dogpile_cache(app: Flask) -> None:
# Log cache configuration
if app.cache:
logger.info("Cache configuration:")
- logger.info(
- " Two-tier memory cache: Hot (5 min TTL), Warm (1 hour TTL)"
- )
- logger.info(" Namespaces: settings, api_keys, metrics, search_results")
- logger.info(" Security: HMAC-SHA256 key hashing enabled")
+ logger.info(" Simple in-memory cache (1 hour TTL)")
+ logger.info(" Namespaces: settings, api_keys, search_results")
diff --git a/src/local_deep_research/memory_cache/config.py b/src/local_deep_research/memory_cache/config.py
index 483facdc2f..966cad1c35 100644
--- a/src/local_deep_research/memory_cache/config.py
+++ b/src/local_deep_research/memory_cache/config.py
@@ -4,9 +4,6 @@ This module provides a simple in-memory caching system optimized for per-user
encrypted databases with SQLAlchemy and SQLCipher.
"""
-import hashlib
-import hmac
-import os
import threading
from typing import Any, Dict, Optional, Union
@@ -14,72 +11,26 @@ from dogpile.cache import CacheRegion, make_region
from dogpile.cache.api import NO_VALUE
from loguru import logger
-from ..config.paths import get_data_directory
-
-# Get project static directory
-PROJECT_STATIC_DIR = get_data_directory()
-
# Thread-local storage for cache regions (matches session pattern)
thread_local = threading.local()
# Cache configuration constants
DEFAULT_CACHE_TTL = 3600 # 1 hour
-CACHE_KEY_SECRET = os.environ.get("CACHE_KEY_SECRET", None)
-if not CACHE_KEY_SECRET:
- # Generate a cache key secret similar to Flask SECRET_KEY
- import secrets
-
- cache_secret_file = os.path.join(PROJECT_STATIC_DIR, ".cache_key_secret")
- if os.path.exists(cache_secret_file):
- try:
- with open(cache_secret_file, "r") as f:
- CACHE_KEY_SECRET = f.read().strip()
- except Exception:
- CACHE_KEY_SECRET = secrets.token_hex(32)
- else:
- # Generate a new cache key on first run
- CACHE_KEY_SECRET = secrets.token_hex(32)
- try:
- os.makedirs(os.path.dirname(cache_secret_file), exist_ok=True)
- with open(cache_secret_file, "w") as f:
- # CodeQL: This is intentional - cache key needs to persist across restarts
- # File is protected with 0o600 permissions (owner read/write only)
- f.write(CACHE_KEY_SECRET) # nosec B108
- os.chmod(cache_secret_file, 0o600) # Secure file permissions
- logger.info("Generated new CACHE_KEY_SECRET for this installation")
- except Exception:
- pass # Use the generated key even if we can't save it
-
-
-def secure_cache_key(user_id: str, key_parts: list) -> str:
- """Generate secure cache key using HMAC-SHA256.
-
- Args:
- user_id: User identifier
- key_parts: List of key components
-
- Returns:
- Secure hash of the cache key
- """
- key_material = f"{user_id}:{':'.join(str(p) for p in key_parts)}"
- return hmac.new(
- CACHE_KEY_SECRET.encode(), key_material.encode(), hashlib.sha256
- ).hexdigest()[:32]
def get_namespaced_key(user_id: str, namespace: str, key: str) -> str:
- """Create namespaced cache key with security.
+ """Create namespaced cache key.
Args:
user_id: User identifier
- namespace: Cache namespace (e.g., 'settings', 'metrics')
+ namespace: Cache namespace (e.g., 'settings', 'api_keys')
key: Specific cache key
Returns:
- Namespaced and secured cache key
+ Namespaced cache key
"""
- secure_id = secure_cache_key(user_id, [namespace, key])
- return f"ldr:{user_id}:{namespace}:{secure_id}"
+ # Simple string concatenation for in-memory cache keys
+ return f"ldr:{user_id}:{namespace}:{key}"
def create_null_cache_region() -> CacheRegion: