当前位置: 首页>>代码示例>>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;未经允许,请勿转载。