Accepted (November 2024)
RapidPM needs caching for:
We needed to decide:
Use Redis for Celery broker and selective metadata caching. Do NOT cache frequently-changing data like tasks or billing.
| Data Type | Cache? | Reason |
|---|---|---|
| Company metadata | Yes | Rarely changes |
| Project metadata | Yes | Rarely changes |
| User preferences | Yes | Rarely changes |
| Tasks | No | Frequently updated |
| Timesheets | No | Real-time accuracy needed |
| Billing data | No | Must be accurate |
| Documents | No | Too large, managed by OnlyOffice |
Redis Configuration:
REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost')
REDIS_PORT = int(os.environ.get('REDIS_PORT', 6379))
REDIS_DB = int(os.environ.get('REDIS_DB', 0))
REDIS_URL = f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_DB}"
Celery Broker:
celery_app = Celery(
'rapidpm',
broker=os.environ.get('REDIS_URL'),
backend=os.environ.get('REDIS_URL')
)
Session Storage (OnlyOffice):
# Active editing sessions
session:{artefact_id}:users → SET of user IDs
session:{artefact_id}:last_activity → timestamp
Metadata Caching (Example):
# Cache company settings (1 hour TTL)
cache_key = f"company:{company_id}:settings"
cached = redis_client.get(cache_key)
if cached:
return json.loads(cached)
else:
settings = db.query(Company).get(company_id).settings
redis_client.setex(cache_key, 3600, json.dumps(settings))
return settings
TTL-based (Time To Live):
Explicit invalidation:
company:{id}:* keysproject:{id}:* keysNo caching (avoid invalidation):
# docker-compose.yml
redis:
image: redis:5.0-alpine
command: redis-server --maxmemory 512mb --maxmemory-policy allkeys-lru
Cache all database queries.
Rejected because:
Only use Redis for Celery, no data caching.
Considered viable, but:
Use Memcached instead of Redis.
Rejected because: