當前位置: 首頁>>代碼示例>>Python>>正文


Python current.cache方法代碼示例

本文整理匯總了Python中gluon.current.cache方法的典型用法代碼示例。如果您正苦於以下問題:Python current.cache方法的具體用法?Python current.cache怎麽用?Python current.cache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gluon.current的用法示例。


在下文中一共展示了current.cache方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __call__

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import cache [as 別名]
def __call__(self, key, f,
                 time_expire=DEFAULT_TIME_EXPIRE):
        """
        Tries to retrieve the value corresponding to `key` from the cache if the
        object exists and if it did not expire, else it calls the function `f`
        and stores the output in the cache corresponding to `key`. It always
        returns the function that is returned.

        Args:
            key(str): the key of the object to be stored or retrieved
            f(function): the function whose output is to be cached.

                If `f` is `None` the cache is cleared.
            time_expire(int): expiration of the cache in seconds.

                It's used to compare the current time with the time
                when the requested object was last saved in cache. It does not
                affect future requests. Setting `time_expire` to 0 or negative
                value forces the cache to refresh.
        """
        raise NotImplementedError 
開發者ID:HackPucBemobi,項目名稱:touch-pay-client,代碼行數:23,代碼來源:cache.py

示例2: initialize

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import cache [as 別名]
def initialize(self):
        if self.initialized:
            return
        else:
            self.initialized = True

        folder = self.folder
        request = self.request

        # Lets test if the cache folder exists, if not
        # we are going to create it
        folder = os.path.join(folder or request.folder, 'cache')

        if not os.path.exists(folder):
            os.mkdir(folder)

        self.storage = CacheOnDisk.PersistentStorage(folder) 
開發者ID:HackPucBemobi,項目名稱:touch-pay-client,代碼行數:19,代碼來源:cache.py

示例3: __init__

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import cache [as 別名]
def __init__(self, request):
        """
        Args:
            request: the global request object
        """
        # GAE will have a special caching
        if have_settings and settings.global_settings.web2py_runtime_gae:
            from gluon.contrib.gae_memcache import MemcacheClient
            self.ram = self.disk = MemcacheClient(request)
        else:
            # Otherwise use ram (and try also disk)
            self.ram = CacheInRam(request)
            try:
                self.disk = CacheOnDisk(request)
            except IOError:
                logger.warning('no cache.disk (IOError)')
            except AttributeError:
                # normally not expected anymore, as GAE has already
                # been accounted for
                logger.warning('no cache.disk (AttributeError)') 
開發者ID:HackPucBemobi,項目名稱:touch-pay-client,代碼行數:22,代碼來源:cache.py

示例4: lazy_cache

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import cache [as 別名]
def lazy_cache(key=None, time_expire=None, cache_model='ram'):
    """
    Can be used to cache any function including ones in modules,
    as long as the cached function is only called within a web2py request

    If a key is not provided, one is generated from the function name
    `time_expire` defaults to None (no cache expiration)

    If cache_model is "ram" then the model is current.cache.ram, etc.
    """
    def decorator(f, key=key, time_expire=time_expire, cache_model=cache_model):
        key = key or repr(f)

        def g(*c, **d):
            from gluon import current
            return current.cache(key, time_expire, cache_model)(f)(*c, **d)
        g.__name__ = f.__name__
        return g
    return decorator 
開發者ID:HackPucBemobi,項目名稱:touch-pay-client,代碼行數:21,代碼來源:cache.py

示例5: initialize

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import cache [as 別名]
def initialize(self):
        if self.initialized:
            return
        else:
            self.initialized = True

        folder = self.folder
        request = self.request

        # Lets test if the cache folder exists, if not
        # we are going to create it
        folder = os.path.join(folder or request.folder, 'cache')

        if not os.path.exists(folder):
            os.mkdir(folder)

        self.storage = CacheOnDisk.PersistentStorage(folder)
        
        if not CacheAbstract.cache_stats_name in self.storage:
            self.storage[CacheAbstract.cache_stats_name] = {'hit_total': 0, 'misses': 0} 
開發者ID:StuffShare,項目名稱:StuffShare,代碼行數:22,代碼來源:cache.py

示例6: __init__

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import cache [as 別名]
def __init__(self, request):
        """
        Args: 
            request: the global request object
        """
        # GAE will have a special caching
        if have_settings and settings.global_settings.web2py_runtime_gae:
            from gluon.contrib.gae_memcache import MemcacheClient
            self.ram = self.disk = MemcacheClient(request)
        else:
            # Otherwise use ram (and try also disk)
            self.ram = CacheInRam(request)
            try:
                self.disk = CacheOnDisk(request)
            except IOError:
                logger.warning('no cache.disk (IOError)')
            except AttributeError:
                # normally not expected anymore, as GAE has already
                # been accounted for
                logger.warning('no cache.disk (AttributeError)') 
開發者ID:StuffShare,項目名稱:StuffShare,代碼行數:22,代碼來源:cache.py

示例7: clear

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import cache [as 別名]
def clear(self, regex=None):
        """
        Clears the cache of all keys that match the provided regular expression.
        If no regular expression is provided, it clears all entries in cache.

        Args:
            regex: if provided, only keys matching the regex will be cleared,
                otherwise all keys are cleared.
        """

        raise NotImplementedError 
開發者ID:HackPucBemobi,項目名稱:touch-pay-client,代碼行數:13,代碼來源:cache.py

示例8: _clear

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import cache [as 別名]
def _clear(self, storage, regex):
        """
        Auxiliary function called by `clear` to search and clear cache entries
        """
        r = re.compile(regex)
        for key in list(storage.keys()):
            if r.match(str(key)):
                del storage[key]
        return 
開發者ID:HackPucBemobi,項目名稱:touch-pay-client,代碼行數:11,代碼來源:cache.py

示例9: with_prefix

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import cache [as 別名]
def with_prefix(cache_model, prefix):
        """
        allow replacing cache.ram with cache.with_prefix(cache.ram,'prefix')
        it will add prefix to all the cache keys used.
        """
        return lambda key, f, time_expire=DEFAULT_TIME_EXPIRE, prefix=prefix: cache_model(prefix + key, f, time_expire) 
開發者ID:HackPucBemobi,項目名稱:touch-pay-client,代碼行數:8,代碼來源:cache.py

示例10: _clear

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import cache [as 別名]
def _clear(self, storage, regex):
        """
        Auxiliary function called by `clear` to search and clear cache entries
        """
        r = re.compile(regex)
        for key in storage.keys():
            if r.match(str(key)):
                del storage[key]
        return 
開發者ID:lucadealfaro,項目名稱:true_review_web2py,代碼行數:11,代碼來源:cache.py

示例11: with_prefix

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import cache [as 別名]
def with_prefix(cache_model, prefix):
        """
        allow replacing cache.ram with cache.with_prefix(cache.ram,'prefix')
        it will add prefix to all the cache keys used.
        """
        return lambda key, f, time_expire=DEFAULT_TIME_EXPIRE, prefix=prefix:\
            cache_model(prefix + key, f, time_expire) 
開發者ID:lucadealfaro,項目名稱:true_review_web2py,代碼行數:9,代碼來源:cache.py


注:本文中的gluon.current.cache方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。