Skip to content

Conversation

biraj21
Copy link

@biraj21 biraj21 commented Nov 22, 2024

What do these changes do?

This PR adds an invalidate_cache function to the aiocache library, allowing users to explicitly invalidate the cache of a function decorated with @cache. Users can call the method directly on the cached function object with the arguments that were used to generate the cache key. Usage:

await <function_name>.invalidate_cache(*args, **kwargs)

Are there changes in behavior for the user?

Yes, this new functionality provides users with a convenient way to manually invalidate the cache for specific arguments of a cached function, enhancing flexibility and control over cache management.

Related issue number

N/A

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes

@altairmn
Copy link

What's the progress on this feature? it'd be great to have cache invalidation. Otherwise, the workaround for this is very messy.

@Dreamsorcerer
Copy link
Member

I'd prefer to avoid adding more hacks like this onto the old code. This should really wait for #625 to be completed, which may require the other tasks listed before it in the milestone: https://github.com/aio-libs/aiocache/milestone/8

elecnix added a commit to elecnix/aiocache that referenced this pull request Apr 26, 2025
- Refactored @cached and @multi_cached to return a wrapper object with .refresh() and .invalidate() methods.
- refresh: forces a cache update for the given key.
- invalidate: clears the cache for the given key, or clears all if no key is given.

Closes aio-libs#625. Replaces aio-libs#927.
elecnix added a commit to elecnix/aiocache that referenced this pull request Apr 26, 2025
- Refactored @cached and @multi_cached to return a wrapper object with .refresh() and .invalidate() methods.
- refresh: forces a cache update for the given key.
- invalidate: clears the cache for the given key, or clears all if no key is given.

Closes aio-libs#625. Replaces aio-libs#927.
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.

3 participants