Skip to content

Commit

Permalink
Use kwonly args to clean up some code
Browse files Browse the repository at this point in the history
  • Loading branch information
Suor committed Jun 21, 2020
1 parent fc7e6f4 commit 4d43f88
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions cacheops/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def cache_thing(prefix, cache_key, data, cond_dnfs, timeout, dbs=(), precall_key
)


def cached_as(*samples, **kwargs):
def cached_as(*samples, timeout=None, extra=None, lock=None, keep_fresh=False,
key_func=func_cache_key):
"""
Caches results of a function and invalidates them same way as given queryset(s).
NOTE: Ignores queryset cached ops settings, always caches.
Expand All @@ -67,15 +68,8 @@ def cached_as(*samples, **kwargs):
invalidated during the function call. This prevents prolonged caching of
stale data.
"""
timeout = kwargs.pop('timeout', None)
extra = kwargs.pop('extra', None)
key_func = kwargs.pop('key_func', func_cache_key)
lock = kwargs.pop('lock', None)
keep_fresh = kwargs.pop('keep_fresh', False)
if not samples:
raise TypeError('Pass a queryset, a model or an object to cache like')
if kwargs:
raise TypeError('Unexpected keyword arguments %s' % ', '.join(kwargs))

# If we unexpectedly get list instead of queryset return identity decorator.
# Paginator could do this when page.object_list is empty.
Expand Down

0 comments on commit 4d43f88

Please sign in to comment.