Skip to content

Conversation

lucasmrdt
Copy link

What do these changes do?

Adds a new LimitedSizeMemoryCache backend that extends SimpleMemoryCache with LRU (Least Recently Used) eviction policy and configurable size limits. The cache automatically evicts least recently used items when the size limit is exceeded.

Are there changes in behavior for the user?

Yes, users now have access to a memory-constrained cache backend. The new cache:

  • Accepts a max_size_mb parameter (default: 64MB) to limit total cache size
  • Uses LRU eviction when the size limit is reached
  • Optionally raises MemoryError when trying to cache items larger than the limit (via raise_on_oversize=True)
  • Is available as aiocache.LimitedSizeMemoryCache and included in the default cache backends list

Related issue number

None

Checklist

  • I think the code is well written
  • Unit tests for the changes exist (in tests/ut/backends/test_limited_memory.py)
  • Documentation reflects the changes (in docs/caches.rst)

@Dreamsorcerer
Copy link
Member

Dreamsorcerer commented Aug 2, 2025

This seems too close to #1027. I think anything more complex should be done in an external library and linked from the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants