Adds dogpile.cache support to your Flask application
Project description
Easy to Use
# ==================== config.py ====================
DOGPILE_CACHE_URLS = ["127.0.0.1:11211"]
DOGPILE_CACHE_REGIONS = [
('hour', 3600),
('day', 3600 * 24),
('month', 3600 * 24 * 31),
]
# Default settings:
# DOGPILE_CACHE_BACKEND = 'dogpile.cache.memcached'
# ==================== app.py ====================
import config
from flask import Flask
from flask.ext.dogpile_cache import DogpileCache
app = Flask(__name__)
app.config.from_object(config)
cache = DogpileCache()
cache.init_app(app)
# Alternative way: cache = DogpileCache(app)
@cache.region('hour')
def cached_func(*args):
print "Heavy computation here", args
return args
value = cached_func()
cache.invalidate(cached_func, *args) # Invalidating cache for cached_func
cache.refresh(cached_func, *args) # Refreshing cache for cached_func
cache.set(cached_func, value, *args) # Setting custom value for cached_func
cache.invalidate_region('hour') # Invalidate cache for all funcs
# decorated with @cache.region('hour')
cache.invalidate_all_regions() # Invalidate cache for all funcs
# decorated with @cache.region
Easy to Install
$ pip install Flask-Dogpile-Cache
Links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file Flask-Dogpile-Cache-0.2.tar.gz
.
File metadata
- Download URL: Flask-Dogpile-Cache-0.2.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4304cd647e0b54cfecb82d32f4ac69995c514686d75b364b7de40f13897891f6 |
|
MD5 | ad64f3296c1f6e3fe6d50f5b14ebe782 |
|
BLAKE2b-256 | 0d436c0898096fd0ad31e3576a92d1f1ddd05f23bdd1e4791eee841441214dbf |