def test_converts_expiration_time_to_int(empty_config):
    configure_dogpile_cache({
        'dogpile_cache.regions': 'foo',
        'dogpile_cache.backend': 'dogpile.cache.memory',
        'dogpile_cache.expiration_time': '1',
    })
    assert get_region('foo').expiration_time == 1
Beispiel #2
0
def configure_dogpile_cache(event):
    config = zope.app.appsetup.product.getProductConfiguration('zeit.cms')
    settings = {'dogpile_cache.regions': config['cache-regions']}
    for region in re.split(r'\s*,\s*', config['cache-regions']):
        settings['dogpile_cache.%s.backend' % region] = 'dogpile.cache.memory'
        settings['dogpile_cache.%s.expiration_time' %
                 region] = config['cache-expiration-%s' % region]
    pyramid_dogpile_cache2.configure_dogpile_cache(settings)
def test_sets_backend_for_regions(empty_config):
    configure_dogpile_cache({
        'dogpile_cache.regions': 'foo, bar',
        'dogpile_cache.backend': 'dogpile.cache.memory',
        'dogpile_cache.expiration_time': '1',
    })
    assert isinstance(get_region('foo').backend, MemoryBackend)
    assert isinstance(get_region('bar').backend, MemoryBackend)
def test_unconfigured_region_raises(empty_config):
    get_region('bar')
    with pytest.raises(dogpile.cache.exception.RegionNotConfigured):
        configure_dogpile_cache({
            'dogpile_cache.regions': 'foo',
            'dogpile_cache.backend': 'dogpile.cache.memory',
            'dogpile_cache.expiration_time': '1',
        })
Beispiel #5
0
def configure_dogpile_cache(event):
    config = zope.app.appsetup.product.getProductConfiguration('zeit.cms')
    pyramid_dogpile_cache2.configure_dogpile_cache({
        'dogpile_cache.backend':
        'dogpile.cache.memory',
        'dogpile_cache.regions':
        'config',
        'dogpile_cache.config.expiration_time':
        config['cache-expiration-config']
    })
def test_sets_pylibmc_behaviours(empty_config, monkeypatch):
    monkeypatch.setattr(
        dogpile.cache.backends.memcached.PylibmcBackend, '_imports',
        lambda self: None)
    configure_dogpile_cache({
        'dogpile_cache.regions': 'foo',
        'dogpile_cache.backend': 'dogpile.cache.pylibmc',
        'dogpile_cache.pylibmc_url': 'http://localhost:8899',
        'dogpile_cache.expiration_time': '1',
        'dogpile_cache.pylibmc_behavior.send_timeout': '5',
    })
    assert get_region('foo').backend.behaviors == {'send_timeout': 5}
def test_sets_memcache_expire_time_to_later_than_expiration_time(
        empty_config, monkeypatch):
    monkeypatch.setattr(
        dogpile.cache.backends.memcached.PylibmcBackend, '_imports',
        lambda self: None)
    configure_dogpile_cache({
        'dogpile_cache.regions': 'foo',
        'dogpile_cache.backend': 'dogpile.cache.pylibmc',
        'dogpile_cache.pylibmc_url': 'http://localhost:8899',
        'dogpile_cache.expiration_time': '1',
        'dogpile_cache.memcache_expire_time_interval': '5'
    })
    assert get_region('foo').backend.memcached_expire_time == 6