Exemplo n.º 1
0
    def get_cache(self, cache_size):
        global _cache
        if _cache is None:
            _cache = lru.LRU(cache_size)

            class hook(client.hook):
                def on_new_version(self, page):
                    if page.key in _cache:
                        _cache.delete(page.key)

        return _cache
Exemplo n.º 2
0
def load_config(config_file):
    import yaml
    from infogami.infobase import config as infobase_config
    from infogami.infobase import server as infobase_server
    from infogami.infobase import lru

    def storify(d):
        if isinstance(d, dict):
            return web.storage((k, storify(v)) for k, v in d.items())
        elif isinstance(d, list):
            return [storify(x) for x in d]
        else:
            return d

    # load config
    with open(config_file) as in_file:
        runtime_config = yaml.safe_load(in_file)

    # update config
    for k, v in runtime_config.items():
        setattr(config, k, storify(v))

    for k, v in runtime_config.get('infobase', {}).items():
        setattr(infobase_config, k, storify(v))

    # setup python path
    sys.path += config.get('python_path', [])

    config.db_parameters = infobase_server.parse_db_parameters(
        config.db_parameters)
    web.config.db_parameters = config.db_parameters

    # setup infobase
    if config.get('cache_size'):
        from infogami.infobase import cache

        cache.global_cache = lru.LRU(config.cache_size)

    if config.get('secret_key'):
        infobase_config.secret_key = config.secret_key

    # setup smtp_server
    if config.get('smtp_server'):
        web.config.smtp_server = config.smtp_server
Exemplo n.º 3
0
    def clear(self):
        self.memcache_client.flush_all()

_cache_classes = {}
def register_cache(type, klass):
    _cache_classes[type] = klass

register_cache('lru', lru.LRU)
register_cache('memcache', MemcachedDict)

def create_cache(type, **kw):
    klass = _cache_classes.get(type) or NoneDict
    return klass(**kw)

special_cache = {}
global_cache = lru.LRU(200)

def loadhook():
    web.ctx.new_objects = {}
    web.ctx.local_cache = {}
    web.ctx.locally_added = {}

def unloadhook():
    """Called at the end of every request."""
    d = {}
    d.update(web.ctx.locally_added)
    d.update(web.ctx.new_objects)

    if d:
        global_cache.update(d)