@@ -57,14 +57,15 @@ def f(a, b=2):
5757 'used `@cache`, while you should have used '
5858 '`@cache()`' % max_size )
5959
60- if max_size == infinity :
60+ def decorator ( function ) :
6161
62- def decorator (function ):
63- # In case we're being given a function that is already cached:
64- if getattr (function , 'is_cached' , False ): return function
62+ # In case we're being given a function that is already cached:
63+ if getattr (function , 'is_cached' , False ): return function
64+
65+ if max_size == infinity :
6566
6667 cache_dict = {}
67-
68+
6869 def cached (function , * args , ** kwargs ):
6970 sleek_call_args = \
7071 SleekCallArgs (cache_dict , function , * args , ** kwargs )
@@ -74,12 +75,8 @@ def cached(function, *args, **kwargs):
7475 cached ._cache [sleek_call_args ] = value = \
7576 function (* args , ** kwargs )
7677 return value
77-
78- else : # max_size < infinity
79-
80- def decorator (function ):
81- # In case we're being given a function that is already cached:
82- if getattr (function , 'is_cached' , False ): return function
78+
79+ else : # max_size < infinity
8380
8481 cache_dict = OrderedDict ()
8582
@@ -100,12 +97,13 @@ def cached(function, *args, **kwargs):
10097 cached ._cache = cache_dict
10198 cached .is_cached = True
10299
100+ result = decorator_tools .decorator (cached , function )
101+
103102 def cache_clear ():
104103 '''Clear the cache, deleting all saved results.'''
105- cache .clear ()
106-
107- result = decorator_tools .decorator (cached , function )
108- result .cache_clear = cached ._cache .clear
104+ cached ._cache .clear ()
105+ result .cache_clear = cache_clear
106+
109107 return result
110108
111109 return decorator
0 commit comments