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

Allow all parameters in the cache config, and override them in specific usages #387

Open
jcugat opened this issue Mar 12, 2018 · 2 comments
Labels

Comments

@jcugat
Copy link
Contributor

jcugat commented Mar 12, 2018

When setting the cache config, I'd like to set there default values (for TTL and namespace for example):

caches.set_config({
    'default': {
        'cache': "aiocache.SimpleMemoryCache",
        'namespace': 'my_namespace',
        'ttl': 60,
    },
})

From that point, all the usages of the default cache would use the namespace and ttl set, unless passed explicitly in decorators and calls:

@cached(alias='default')
async def something_cached(self):
    # This would cache with the default parameters defined in the config
    return await do_stuff()

@cached(alias='default', namespace='another_namespace', ttl=3600)
async def something_else_cached(self):
    # This would cache with the parameters defined in the decorator instead of the config
    return await do_stuff()

# Same for these
caches.get('default').get('foo', default=False, namespace='bar_namespace')
caches.get('default').set('foo', True, namespace='bar_namespace', ttl=86400)
@argaen
Copy link
Member

argaen commented Mar 12, 2018

There are two things here.

On one hand is the part of specifying all the parameters through config. This is already possible except for TTL but because there is no instance attribute for attribute, its just per function. If you want this, we could add ttl in the class constructor too.

On the other hand is the part of overriding with the specifics you pass in the decorator. I guess we could do that in https://github.com/argaen/aiocache/blob/master/aiocache/decorators.py#L59, if there is alias load the config and then create new cache with the new args if passed.

@shizidushu
Copy link

I use cachedRedis = functools.partial(cached, ttl=60, alias='default'), it seems working.

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

No branches or pull requests

3 participants