def _get_cache(): _cache = g.get('_oauth_cache') if _cache: return _cache _cache = FileSystemCache(current_app.config['OAUTH_CACHE_DIR']) g._oauth_cache = _cache return _cache
def __init__(self, cache_dir, threshold, mode, key_prefix, use_signer=False, permanent=True): from cachelib.file import FileSystemCache self.cache = FileSystemCache(cache_dir, threshold=threshold, mode=mode) self.key_prefix = key_prefix self.use_signer = use_signer self.permanent = permanent
def __init__(self, cache_dir, threshold, mode, key_prefix, use_signer=False, permanent=True): from cachelib.file import FileSystemCache self.cache = FileSystemCache(cache_dir, threshold=threshold, mode=mode) self.key_prefix = key_prefix self.use_signer = use_signer self.permanent = permanent self.has_same_site_capability = hasattr(self, "get_cookie_samesite")
# The SQLAlchemy connection string. SQLALCHEMY_DATABASE_URI = "%s://%s:%s@%s:%s/%s" % ( DATABASE_DIALECT, DATABASE_USER, DATABASE_PASSWORD, DATABASE_HOST, DATABASE_PORT, DATABASE_DB, ) REDIS_HOST = get_env_variable("REDIS_HOST") REDIS_PORT = get_env_variable("REDIS_PORT") REDIS_CELERY_DB = get_env_variable("REDIS_CELERY_DB", 0) REDIS_RESULTS_DB = get_env_variable("REDIS_CELERY_DB", 1) RESULTS_BACKEND = FileSystemCache("/app/superset_home/sqllab") class CeleryConfig(object): BROKER_URL = f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_CELERY_DB}" CELERY_RESULT_BACKEND = f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_RESULTS_DB}" CELERY_TASK_PROTOCOL = 1 CELERY_IMPORTS = ( 'superset.sql_lab', 'superset.tasks', ) CELERYD_LOG_LEVEL = 'DEBUG' CELERYD_PREFETCH_MULTIPLIER = 10 CELERY_ACKS_LATE = True CELERY_ANNOTATIONS = { "tasks.add": {
from functools import wraps from cachelib.file import FileSystemCache from mongoengine.base import BaseField from mongoengine.errors import SaveConditionError import logging import itertools import json from scout.libs.redislib import RedisLib from scout.libs.aspire import Aspire db = MongoEngine() assets = Environment() limiter = Limiter(key_func=get_ipaddr) redis = RedisLib() cache = FileSystemCache('./.cache/') logger = logging.getLogger('scout') formatter = logging.Formatter( "[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s") aspire = Aspire() def UTC(): return datetime.now(timezone.utc) def ignored_default(default_val, *exceptions): def dec(function): def _dec(*args, **kwargs): try: return function(*args, **kwargs)
def set_cache(key, value, timeout=15, cache_dir=None): global cache if cache is None: cache = FileSystemCache(cache_dir or get_cache_dir()) cache.set(str(key), value, timeout=timeout)
def get_cache(key, cache_dir=None): global cache if cache is None: cache = FileSystemCache(cache_dir or get_cache_dir()) return cache.get(str(key))
def __init__(self, config: Config): self.cache = FileSystemCache(config.session_cache_dir) self.session_lifetime = config.session_lifetime
Server: Werkzeug/0.9.4 Python/2.7.5+ X-Cache: miss 1000 """ from __future__ import division, unicode_literals from six.moves.http_client import BAD_REQUEST, OK from time import sleep from cachelib.file import FileSystemCache from flask import Flask, render_template, request from flask.ext.webcache import easy_setup, modifiers app = Flask(__name__) werkzeug_cache = FileSystemCache('/tmp/.sleepycalc') easy_setup(app, werkzeug_cache) PLAINTEXT = (('Content-Type', 'text/plain'), ) @app.route("/") def index(): return render_template("index.html") @app.route("/addition") @modifiers.cache_for(seconds=30) def addition(): try: term1, term2 = int(request.args['term1']), int(request.args['term2'])