diff options
Diffstat (limited to 'examples/beaker_caching/environment.py')
| -rw-r--r-- | examples/beaker_caching/environment.py | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/examples/beaker_caching/environment.py b/examples/beaker_caching/environment.py index cdf1794fd..ea946606c 100644 --- a/examples/beaker_caching/environment.py +++ b/examples/beaker_caching/environment.py @@ -4,10 +4,29 @@ Establish data / cache file paths, and configurations, bootstrap fixture data if necessary. """ -import meta, model, fixture_data +import caching_query from sqlalchemy import create_engine +from sqlalchemy.orm import scoped_session, sessionmaker +from sqlalchemy.ext.declarative import declarative_base +from beaker import cache import os +# Beaker CacheManager. A home base for cache configurations. +cache_manager = cache.CacheManager() + +# scoped_session. Apply our custom CachingQuery class to it, +# using a callable that will associate the cache_manager +# with the Query. +Session = scoped_session( + sessionmaker( + query_cls=caching_query.query_callable(cache_manager) + ) + ) + +# global declarative base class. +Base = declarative_base() + + root = "./beaker_data/" if not os.path.exists(root): @@ -19,10 +38,10 @@ if not os.path.exists(root): dbfile = os.path.join(root, "beaker_demo.db") engine = create_engine('sqlite:///%s' % dbfile, echo=True) -meta.Session.configure(bind=engine) +Session.configure(bind=engine) # configure the "default" cache region. -meta.cache_manager.regions['default'] ={ +cache_manager.regions['default'] ={ # using type 'file' to illustrate # serialized persistence. In reality, @@ -39,6 +58,10 @@ meta.cache_manager.regions['default'] ={ } installed = False -if not os.path.exists(dbfile): - fixture_data.install() - installed = True
\ No newline at end of file + +def bootstrap(): + global installed + import fixture_data + if not os.path.exists(dbfile): + fixture_data.install() + installed = True
\ No newline at end of file |
