Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/crewai-files/src/crewai_files/cache/upload_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ async def aclear(self) -> int:
count = sum(len(keys) for keys in self._provider_keys.values())
await self._cache.clear(namespace=self.namespace)
self._provider_keys.clear()
self._key_access_order.clear()

if count > 0:
logger.debug(f"Cleared {count} cache entries")
Expand Down
17 changes: 17 additions & 0 deletions lib/crewai-files/tests/test_upload_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,23 @@ def test_clear(self):
assert cleared == 2
assert len(cache) == 0

def test_clear_resets_eviction_order(self):
"""Entries added after clear must still obey max_entries."""
cache = UploadCache(max_entries=2)
for index in range(2):
cache.set_by_hash(
f"old-{index}", "text/plain", "gemini", file_id=f"old-{index}"
)

cache.clear()

for index in range(3):
cache.set_by_hash(
f"new-{index}", "text/plain", "gemini", file_id=f"new-{index}"
)

assert len(cache) <= 2

def test_get_all_for_provider(self):
"""Test getting all cached uploads for a provider."""
cache = UploadCache()
Expand Down
Loading