Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove aiocache.Cache and alias support #948

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

mikeoconnor0308
Copy link

What do these changes do?

Removes factory.py and associated factory tooling. Updates all the tests and documentation to reflect the changes.

Added a Migration guide to start documenting the changes for a v1 release.

Are there changes in behavior for the user?

  • The aiocache.Cache class has been removed. Instead, use the specific cache class directly. For example, use aiocache.RedisCache instead of aiocache.Cache.REDIS.
  • Caches should be fully instantiated when passed to decorators, rather than being instantiated with a factory function
  • Cache aliases have been removed. Create an instance of the cache class directly instead.

Related issue number

Closes #677

Checklist

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

cache.multi_get.return_value = [None]
get_c.side_effect = [cache, None]
async def test_reuses_cache_instance(self, mock_cache):
# TODO @review can probably just remove this test.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted, this test is a bit superfluous now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, drop it.

@@ -8,7 +8,7 @@

logger = logging.getLogger(__name__)

AIOCACHE_CACHES: Dict[str, Type[BaseCache[Any]]] = {SimpleMemoryCache.NAME: SimpleMemoryCache}
_AIOCACHE_CACHES: Dict[str, Type[BaseCache[Any]]] = {SimpleMemoryCache.NAME: SimpleMemoryCache}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the only purpose of this is to load them into __all__ now.
In which case, the SimpleMemory Cache can probably be put in directly, and this can just be initialised to an empty list (there's no point of a dict anymore).

Comment on lines 34 to 39
self,
ttl=SENTINEL,
namespace="",
key_builder=None,
skip_cache_func=lambda x: False,
cache=Cache.MEMORY,
serializer=None,
plugins=None,
alias=None,
cache=None,
noself=False,
Copy link
Member

@Dreamsorcerer Dreamsorcerer Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking about this design, maybe we want to allow the cache to be passed as a positional argument (i.e. the common one used in most cases), and everything else should be keyword only. So, like:

self,
cache=None,
*,
ttl=SENTINEL,
...

I'm also wondering if we should make the cache a required argument... Technically, the memory cache has no shoutdown logic, so it doesn't really make a difference (though it'd encourage reusing an instance across multiple decorators).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I like the idea of both your points - the default of using memory could be confusing if you expected redis (especially for folks migrating from the old alias stuff).

Comment on lines 219 to +224
self,
keys_from_attr,
namespace="",
key_builder=None,
skip_cache_func=lambda k, v: False,
ttl=SENTINEL,
cache=Cache.MEMORY,
serializer=None,
plugins=None,
alias=None,
**kwargs,
cache=None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same positional/keyword here.

docs/index.rst Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that'll be very useful to add to as we get to the final release.

Copy link
Member

@Dreamsorcerer Dreamsorcerer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking at this. Seems to a very thorough PR.

Co-authored-by: Sam Bull <[email protected]>
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.

Remove factory
2 participants