3
Establish data / cache file paths, and configurations,
4
bootstrap fixture data if necessary.
8
from sqlalchemy import create_engine
9
from sqlalchemy.orm import scoped_session, sessionmaker
10
from sqlalchemy.ext.declarative import declarative_base
11
from dogpile.cache.region import make_region
15
# dogpile cache regions. A home base for cache configurations.
19
# scoped_session. Apply our custom CachingQuery class to it,
20
# using a callable that will associate the dictionary
21
# of regions with the Query.
22
Session = scoped_session(
24
query_cls=caching_query.query_callable(regions)
28
# global declarative base class.
29
Base = declarative_base()
31
root = "./dogpile_data/"
33
if not os.path.exists(root):
34
raw_input("Will create datafiles in %r.\n"
35
"To reset the cache + database, delete this directory.\n"
36
"Press enter to continue.\n" % root
40
dbfile = os.path.join(root, "dogpile_demo.db")
41
engine = create_engine('sqlite:///%s' % dbfile, echo=True)
42
Session.configure(bind=engine)
45
def md5_key_mangler(key):
46
"""Receive cache keys as long concatenated strings;
47
distill them into an md5 hash.
50
return md5.md5(key).hexdigest()
52
# configure the "default" cache region.
53
regions['default'] = make_region(
54
# the "dbm" backend needs
56
key_mangler=md5_key_mangler
58
# using type 'file' to illustrate
59
# serialized persistence. Normally
60
# memcached or similar is a better choice
65
"filename": os.path.join(root, "cache.dbm")
69
# optional; call invalidate() on the region
70
# once created so that all data is fresh when
71
# the app is restarted. Good for development,
72
# on a production system needs to be used carefully
73
# regions['default'].invalidate()
81
if not os.path.exists(dbfile):
82
fixture_data.install()
b'\\ No newline at end of file'