Skip to content

Commit

Permalink
add use cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed-XCF committed Jan 4, 2023
1 parent 1eb7144 commit af8032a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion redis_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import orjson
from redis import Redis, RedisError

__all__ = ["redis_property", "cache_ttl", "cache_disable", "no_cache"]
__all__ = ["redis_property", "cache_ttl", "cache_disable", "no_cache", "use_cache"]

_redis_cli = None
_default_cache_ttl = 24 * 60 * 60
Expand Down Expand Up @@ -152,3 +152,15 @@ def wrapper(*args, **kwargs):
cache_disable.reset(token)

return wrapper


def use_cache(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
token = cache_disable.set(False)
try:
return func(*args, **kwargs)
finally:
cache_disable.reset(token)

return wrapper

0 comments on commit af8032a

Please sign in to comment.