summaryrefslogtreecommitdiff
path: root/sqlparse/utils.py
diff options
context:
space:
mode:
authorJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-05-19 19:21:00 +0200
committerJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-05-19 19:21:00 +0200
commit7e532bcd9af6f36280f497346d50b4cdd028cfbf (patch)
treea4d93108dc0b74c92d202cd9dec751c9acbdac61 /sqlparse/utils.py
parentec110d64b0a5e9f362e76b9c01ecccbd6932d0a9 (diff)
downloadsqlparse-7e532bcd9af6f36280f497346d50b4cdd028cfbf.tar.gz
Added limit to cache
Diffstat (limited to 'sqlparse/utils.py')
-rw-r--r--sqlparse/utils.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/sqlparse/utils.py b/sqlparse/utils.py
index 0dbb09f..fd6651a 100644
--- a/sqlparse/utils.py
+++ b/sqlparse/utils.py
@@ -6,8 +6,7 @@ Created on 17/05/2012
def memoize_generator(func):
- """
- Memoize decorator for generators
+ """Memoize decorator for generators
Store `func` results in a cache according to their arguments as 'memoize'
does but instead this works on decorators instead of regular functions.
@@ -25,6 +24,12 @@ def memoize_generator(func):
# Not cached, exec and store it
except KeyError:
+ # Reset the cache if we have too much cached entries and start over
+ # In the future would be better to use an OrderedDict and drop the
+ # Least Recent Used entries
+ if len(cache) >= 10:
+ cache.clear()
+
cached = []
for item in func(*args, **kwargs):