Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(7)  |  Call(0)  |  Derive(0)  |  Import(7)
decorator to 'memoize' a function - caching its results

        def memoize(maxsize):
    """decorator to 'memoize' a function - caching its results"""
    def decorating_function(f):
        cache = {}  # map from key to value
        heap = []   # list of keys, in LRU heap
        cursize = 0 # because len() is slow
        def wrapper(*args):
            key = repr(args)
            # performance crap
            _cache=cache
            _heap=heap
            _heappop = heapq.heappop
            _heappush = heapq.heappush
            _time = time.time
            _cursize = cursize
            _maxsize = maxsize
            if not _cache.has_key(key):
                if _cursize == _maxsize:
                    # pop oldest element
                    (_,oldkey) = _heappop(_heap)
                    _cache.pop(oldkey)
                else:
                    _cursize += 1
                # insert this element
                _cache[key] = f(*args)
                _heappush(_heap,(_time(),key))
                wrapper.misses += 1
            else:
                wrapper.hits += 1
            return cache[key]
        wrapper.__doc__ = f.__doc__
        wrapper.__name__ = f.__name__
        wrapper.hits = wrapper.misses = 0
        return wrapper 
    return decorating_function
        


src/o/p/openerp-extra-6.1-HEAD/document_webdav_old/webdav/dav_fs.py   openerp-extra-6.1(Download)
from DAV.davcmd import copyone, copytree, moveone, movetree, delone, deltree
 
from cache import memoize
 
CACHE_SIZE=20000

src/a/d/adhocracy-2.4.1/parts/omelette/adhocracy/lib/logo.py   adhocracy(Download)
 
 
from cache import memoize
import util
 

src/a/d/adhocracy-2.4.1/src/adhocracy/lib/logo.py   adhocracy(Download)
 
 
from cache import memoize
import util
 

src/a/d/adhocracy-2.4.1/installed_eggs/adhocracy/lib/logo.py   adhocracy(Download)
 
 
from cache import memoize
import util
 

src/a/d/adhocracy-HEAD/src/adhocracy/lib/logo.py   adhocracy(Download)
 
 
from cache import memoize
import util
 

src/l/o/locustio-0.7.1/locust/web.py   locustio(Download)
 
from . import runners
from .cache import memoize
from .runners import MasterLocustRunner
from locust.stats import median_from_dict

src/o/p/openerp-document-webdav-7.0.406/dav_fs.py   openerp-document-webdav(Download)
from openerp.tools import misc
 
from cache import memoize
from webdav import mk_lock_response