2013-02-14 15:32:17 +04:00
|
|
|
#!/usr/bin/env python
|
2012-07-30 13:21:32 +04:00
|
|
|
|
|
|
|
"""
|
2017-01-02 16:19:18 +03:00
|
|
|
Copyright (c) 2006-2017 sqlmap developers (http://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
2012-07-30 13:21:32 +04:00
|
|
|
"""
|
|
|
|
|
2012-07-30 12:06:14 +04:00
|
|
|
def cachedmethod(f, cache={}):
|
2012-07-30 13:21:32 +04:00
|
|
|
"""
|
|
|
|
Method with a cached content
|
|
|
|
|
|
|
|
Reference: http://code.activestate.com/recipes/325205-cache-decorator-in-python-24/
|
|
|
|
"""
|
2013-01-30 13:38:11 +04:00
|
|
|
|
2012-07-30 12:06:14 +04:00
|
|
|
def _(*args, **kwargs):
|
2013-02-22 13:49:45 +04:00
|
|
|
try:
|
2017-11-09 14:24:11 +03:00
|
|
|
key = hash((f, tuple(args), frozenset(kwargs.items())))
|
2016-05-14 15:18:34 +03:00
|
|
|
if key not in cache:
|
|
|
|
cache[key] = f(*args, **kwargs)
|
2013-02-22 13:49:45 +04:00
|
|
|
except:
|
2017-11-09 14:24:11 +03:00
|
|
|
key = hash("".join(str(_) for _ in (f, args, kwargs)))
|
2016-05-14 15:18:34 +03:00
|
|
|
if key not in cache:
|
|
|
|
cache[key] = f(*args, **kwargs)
|
|
|
|
|
2012-07-30 12:06:14 +04:00
|
|
|
return cache[key]
|
2013-01-30 13:38:11 +04:00
|
|
|
|
2012-07-30 12:06:14 +04:00
|
|
|
return _
|