equal
deleted
inserted
replaced
109 return cache[arg] |
109 return cache[arg] |
110 else: |
110 else: |
111 def f(*args): |
111 def f(*args): |
112 if args not in cache: |
112 if args not in cache: |
113 cache[args] = func(*args) |
113 cache[args] = func(*args) |
|
114 return cache[args] |
|
115 |
|
116 return f |
|
117 |
|
118 def lrucachefunc(func): |
|
119 '''cache most recent results of function calls''' |
|
120 cache = {} |
|
121 order = [] |
|
122 if func.func_code.co_argcount == 1: |
|
123 def f(arg): |
|
124 if arg not in cache: |
|
125 if len(cache) > 20: |
|
126 del cache[order.pop(0)] |
|
127 cache[arg] = func(arg) |
|
128 else: |
|
129 order.remove(arg) |
|
130 order.append(arg) |
|
131 return cache[arg] |
|
132 else: |
|
133 def f(*args): |
|
134 if args not in cache: |
|
135 if len(cache) > 20: |
|
136 del cache[order.pop(0)] |
|
137 cache[args] = func(*args) |
|
138 else: |
|
139 order.remove(args) |
|
140 order.append(args) |
114 return cache[args] |
141 return cache[args] |
115 |
142 |
116 return f |
143 return f |
117 |
144 |
118 class propertycache(object): |
145 class propertycache(object): |