mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
...
This commit is contained in:
parent
c20d16d4f6
commit
f6865aa595
@ -1,9 +1,9 @@
|
|||||||
def cache(f):
|
def cache(f):
|
||||||
def wrapper(*args):
|
def wrapper(*args):
|
||||||
if not hasattr(f, 'cache'):
|
if not hasattr(f, '__cache__'):
|
||||||
f.cache = {}
|
f.__cache__ = {}
|
||||||
key = args
|
key = args
|
||||||
if key not in f.cache:
|
if key not in f.__cache__:
|
||||||
f.cache[key] = f(*args)
|
f.__cache__[key] = f(*args)
|
||||||
return f.cache[key]
|
return f.__cache__[key]
|
||||||
return wrapper
|
return wrapper
|
@ -1,14 +1,7 @@
|
|||||||
|
from functools import cache
|
||||||
|
|
||||||
def cache(f):
|
@cache
|
||||||
def wrapper(*args):
|
@cache
|
||||||
if not hasattr(f, 'cache'):
|
|
||||||
f.cache = {}
|
|
||||||
key = args
|
|
||||||
if key not in f.cache:
|
|
||||||
f.cache[key] = f(*args)
|
|
||||||
return f.cache[key]
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
@cache
|
@cache
|
||||||
def fib(n):
|
def fib(n):
|
||||||
if n < 2:
|
if n < 2:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user