mirror of https://github.com/kianby/stacosys
homemade caching function
parent
c9b1444bb6
commit
198978a35d
@ -1,3 +1,19 @@
|
||||
import time
|
||||
from sanic import Sanic
|
||||
|
||||
app = Sanic()
|
||||
cache = {}
|
||||
cache_time = 0
|
||||
|
||||
def get_cached(key):
|
||||
global cache
|
||||
global cache_time
|
||||
value = cache.get(key,None)
|
||||
if (time.time() - cache_time) > 120:
|
||||
cache = {}
|
||||
cache_time = time.time()
|
||||
return value
|
||||
|
||||
def set_cached(key, value):
|
||||
global cache
|
||||
cache[key] = value
|
||||
|
Loading…
Reference in New Issue