OWASP / OWASP/Nest

Replace @lru_cache with TTL-based caching for external and dynamic data

Open
#3,447 1 comment 0 reactions 0 assignees View on GitHub
bug enhancement
Dominant language
Python
Stars
451
Forks
707
Avg merge
22h 59m
Merged PRs (30d)
91

Description

## Describe the bug

Several functions in the backend cache **external or frequently changing data** using `@lru_cache`. Since `@lru_cache` has **no expiration mechanism**, the cached values persist for the entire lifetime of the process.

In production, this means data such as news, staff information, GSoC projects, and aggregated counts can become **stale and remain outdated indefinitely**, unless the service is restarted.

This behavior is especially problematic for external integrations where data freshness is expected and correctness depends on periodic updates.

---

## To Reproduce

1. Start the backend server
2. Trigger any code path that calls a function using `@lru_cache` for external data
3. Change the underlying data source (e.g. external API, database update, content refresh)
4. Trigger the same function again
5. Observe that the returned data remains unchanged, even after a long time, until the process restarts

---

## Expected behavior

Caching should respect a **time-based expiration (TTL)** so that external and dynamic data is refreshed automatically after a reasonable interval, without relying on service restarts.

---

## Are you going to work on fixing this?

- [x] Yes
- [ ] No

---

## Screenshots

Not applicable.

---

## Desktop (please complete the following information)

- OS: Not applicable
- Browser: Not applicable
- Version: Not applicable

---

## Smartphone (please complete the following information)

- Device: Not applicable
- OS: Not applicable
- Browser: Not applicable
- Version: Not applicable

---

## Additional context

This affects multiple places in the codebase where `@lru_cache` is used for external or dynamic data, where TTL-based caching would be more appropriate to avoid stale results in production.

Contributor guide

Open the contributing guide

Research direction

No files or tests are named. Search the backend for @lru_cache uses involving news, staff information, GSoC projects, and aggregated counts; determine suitable expiration intervals and identify the existing tests for those paths. Done means dynamic and external results refresh after their TTL without requiring a service restart.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.