Mercurial > kallithea
comparison rhodecode/model/meta.py @ 547:1e757ac98988
renamed project to rhodecode
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 06 Oct 2010 03:18:16 +0200 |
parents | pylons_app/model/meta.py@7afbc45aab28 |
children | 342f8434ed14 |
comparison
equal
deleted
inserted
replaced
546:7c2f5e4d7bbf | 547:1e757ac98988 |
---|---|
1 """SQLAlchemy Metadata and Session object""" | |
2 from sqlalchemy.ext.declarative import declarative_base | |
3 from sqlalchemy.orm import scoped_session, sessionmaker | |
4 from rhodecode.model import caching_query | |
5 from beaker import cache | |
6 import os | |
7 from os.path import join as jn, dirname as dn, abspath | |
8 import time | |
9 | |
10 # Beaker CacheManager. A home base for cache configurations. | |
11 cache_manager = cache.CacheManager() | |
12 | |
13 __all__ = ['Base', 'Session'] | |
14 # | |
15 # SQLAlchemy session manager. Updated by model.init_model() | |
16 # | |
17 Session = scoped_session( | |
18 sessionmaker( | |
19 query_cls=caching_query.query_callable(cache_manager) | |
20 ) | |
21 ) | |
22 | |
23 # The declarative Base | |
24 Base = declarative_base() | |
25 #For another db... | |
26 #Base2 = declarative_base() | |
27 | |
28 #=============================================================================== | |
29 # CACHE OPTIONS | |
30 #=============================================================================== | |
31 cache_dir = jn(dn(dn(dn(abspath(__file__)))), 'data', 'cache') | |
32 if not os.path.isdir(cache_dir): | |
33 os.mkdir(cache_dir) | |
34 # set start_time to current time | |
35 # to re-cache everything | |
36 # upon application startup | |
37 start_time = time.time() | |
38 # configure the "sqlalchemy" cache region. | |
39 cache_manager.regions['sql_cache_short'] = { | |
40 'type':'memory', | |
41 'data_dir':cache_dir, | |
42 'expire':10, | |
43 'start_time':start_time | |
44 } | |
45 cache_manager.regions['sql_cache_med'] = { | |
46 'type':'memory', | |
47 'data_dir':cache_dir, | |
48 'expire':360, | |
49 'start_time':start_time | |
50 } | |
51 cache_manager.regions['sql_cache_long'] = { | |
52 'type':'file', | |
53 'data_dir':cache_dir, | |
54 'expire':3600, | |
55 'start_time':start_time | |
56 } | |
57 #to use cache use this in query | |
58 #.options(FromCache("sqlalchemy_cache_type", "cachekey")) |