##// END OF EJS Templates
moved out sqlalchemy cache from meta to the config files....
marcink -
r609:c1c1cf77 default
parent child Browse files
Show More
@@ -1,6 +1,6 b''
1 ################################################################################
1 ################################################################################
2 ################################################################################
2 ################################################################################
3 # rhodecode - Pylons environment configuration #
3 # rhodecode - Pylons environment configuration #
4 # #
4 # #
5 # The %(here)s variable will be replaced with the parent directory of this file#
5 # The %(here)s variable will be replaced with the parent directory of this file#
6 ################################################################################
6 ################################################################################
@@ -10,7 +10,7 b' debug = true'
10 ################################################################################
10 ################################################################################
11 ## Uncomment and replace with the address which should receive ##
11 ## Uncomment and replace with the address which should receive ##
12 ## any error reports after application crash ##
12 ## any error reports after application crash ##
13 ## Additionally those settings will be used by rhodecode mailing system ##
13 ## Additionally those settings will be used by rhodecode mailing system ##
14 ################################################################################
14 ################################################################################
15 #email_to = admin@localhost
15 #email_to = admin@localhost
16 #error_email_from = paste_error@localhost
16 #error_email_from = paste_error@localhost
@@ -49,14 +49,25 b' cache_dir = %(here)s/data'
49 ####################################
49 ####################################
50 beaker.cache.data_dir=/%(here)s/data/cache/data
50 beaker.cache.data_dir=/%(here)s/data/cache/data
51 beaker.cache.lock_dir=/%(here)s/data/cache/lock
51 beaker.cache.lock_dir=/%(here)s/data/cache/lock
52 beaker.cache.regions=super_short_term,short_term,long_term
52 beaker.cache.regions=super_short_term,short_term,long_term,sql_cache_short,sql_cache_med,sql_cache_long
53 beaker.cache.long_term.type=memory
53 beaker.cache.long_term.type=memory
54 beaker.cache.long_term.expire=36000
54 beaker.cache.long_term.expire=36000
55
55 beaker.cache.short_term.type=memory
56 beaker.cache.short_term.type=memory
56 beaker.cache.short_term.expire=60
57 beaker.cache.short_term.expire=60
58
57 beaker.cache.super_short_term.type=memory
59 beaker.cache.super_short_term.type=memory
58 beaker.cache.super_short_term.expire=10
60 beaker.cache.super_short_term.expire=10
59
61
62 beaker.cache.sql_cache_short.type=memory
63 beaker.cache.sql_cache_short.expire=5
64
65 beaker.cache.sql_cache_med.type=memory
66 beaker.cache.sql_cache_med.expire=360
67
68 beaker.cache.sql_cache_long.type=file
69 beaker.cache.sql_cache_long.expire=3600
70
60 ####################################
71 ####################################
61 ### BEAKER SESSION ####
72 ### BEAKER SESSION ####
62 ####################################
73 ####################################
@@ -1,6 +1,6 b''
1 ################################################################################
1 ################################################################################
2 ################################################################################
2 ################################################################################
3 # rhodecode - Pylons environment configuration #
3 # rhodecode - Pylons environment configuration #
4 # #
4 # #
5 # The %(here)s variable will be replaced with the parent directory of this file#
5 # The %(here)s variable will be replaced with the parent directory of this file#
6 ################################################################################
6 ################################################################################
@@ -9,8 +9,8 b''
9 debug = true
9 debug = true
10 ################################################################################
10 ################################################################################
11 ## Uncomment and replace with the address which should receive ##
11 ## Uncomment and replace with the address which should receive ##
12 ## any error reports after application crash ##
12 ## any error reports after application crash ##
13 ## Additionally those settings will be used by rhodecode mailing system ##
13 ## Additionally those settings will be used by rhodecode mailing system ##
14 ################################################################################
14 ################################################################################
15 #email_to = admin@localhost
15 #email_to = admin@localhost
16 #error_email_from = paste_error@localhost
16 #error_email_from = paste_error@localhost
@@ -49,14 +49,25 b' cache_dir = %(here)s/data'
49 ####################################
49 ####################################
50 beaker.cache.data_dir=/%(here)s/data/cache/data
50 beaker.cache.data_dir=/%(here)s/data/cache/data
51 beaker.cache.lock_dir=/%(here)s/data/cache/lock
51 beaker.cache.lock_dir=/%(here)s/data/cache/lock
52 beaker.cache.regions=super_short_term,short_term,long_term
52 beaker.cache.regions=super_short_term,short_term,long_term,sql_cache_short,sql_cache_med,sql_cache_long
53 beaker.cache.long_term.type=memory
53 beaker.cache.long_term.type=memory
54 beaker.cache.long_term.expire=36000
54 beaker.cache.long_term.expire=36000
55
55 beaker.cache.short_term.type=memory
56 beaker.cache.short_term.type=memory
56 beaker.cache.short_term.expire=60
57 beaker.cache.short_term.expire=60
58
57 beaker.cache.super_short_term.type=memory
59 beaker.cache.super_short_term.type=memory
58 beaker.cache.super_short_term.expire=10
60 beaker.cache.super_short_term.expire=10
59
61
62 beaker.cache.sql_cache_short.type=memory
63 beaker.cache.sql_cache_short.expire=5
64
65 beaker.cache.sql_cache_med.type=memory
66 beaker.cache.sql_cache_med.expire=360
67
68 beaker.cache.sql_cache_long.type=file
69 beaker.cache.sql_cache_long.expire=3600
70
60 ####################################
71 ####################################
61 ### BEAKER SESSION ####
72 ### BEAKER SESSION ####
62 ####################################
73 ####################################
@@ -50,14 +50,25 b' app_instance_uuid = ${app_instance_uuid}'
50 ####################################
50 ####################################
51 beaker.cache.data_dir=/%(here)s/data/cache/data
51 beaker.cache.data_dir=/%(here)s/data/cache/data
52 beaker.cache.lock_dir=/%(here)s/data/cache/lock
52 beaker.cache.lock_dir=/%(here)s/data/cache/lock
53 beaker.cache.regions=super_short_term,short_term,long_term
53 beaker.cache.regions=super_short_term,short_term,long_term,sql_cache_short,sql_cache_med,sql_cache_long
54 beaker.cache.long_term.type=memory
54 beaker.cache.long_term.type=memory
55 beaker.cache.long_term.expire=36000
55 beaker.cache.long_term.expire=36000
56
56 beaker.cache.short_term.type=memory
57 beaker.cache.short_term.type=memory
57 beaker.cache.short_term.expire=60
58 beaker.cache.short_term.expire=60
59
58 beaker.cache.super_short_term.type=memory
60 beaker.cache.super_short_term.type=memory
59 beaker.cache.super_short_term.expire=10
61 beaker.cache.super_short_term.expire=10
60
62
63 beaker.cache.sql_cache_short.type=memory
64 beaker.cache.sql_cache_short.expire=5
65
66 beaker.cache.sql_cache_med.type=memory
67 beaker.cache.sql_cache_med.expire=360
68
69 beaker.cache.sql_cache_long.type=file
70 beaker.cache.sql_cache_long.expire=3600
71
61 ####################################
72 ####################################
62 ### BEAKER SESSION ####
73 ### BEAKER SESSION ####
63 ####################################
74 ####################################
@@ -27,6 +27,7 b' from pylons import config, session, url,'
27 from pylons.controllers.util import abort, redirect
27 from pylons.controllers.util import abort, redirect
28 from rhodecode.lib.utils import get_repo_slug
28 from rhodecode.lib.utils import get_repo_slug
29 from rhodecode.model import meta
29 from rhodecode.model import meta
30 from rhodecode.model.caching_query import FromCache
30 from rhodecode.model.db import User, RepoToPerm, Repository, Permission, \
31 from rhodecode.model.db import User, RepoToPerm, Repository, Permission, \
31 UserToPerm
32 UserToPerm
32 from sqlalchemy.exc import OperationalError
33 from sqlalchemy.exc import OperationalError
@@ -141,7 +142,9 b' def fill_data(user):'
141 @param user:
142 @param user:
142 """
143 """
143 sa = meta.Session
144 sa = meta.Session
144 dbuser = sa.query(User).get(user.user_id)
145 dbuser = sa.query(User).options(FromCache('sql_cache_short',
146 'getuser_%s' % user.user_id))\
147 .get(user.user_id)
145 if dbuser:
148 if dbuser:
146 user.username = dbuser.username
149 user.username = dbuser.username
147 user.is_admin = dbuser.admin
150 user.is_admin = dbuser.admin
@@ -166,11 +169,14 b' def fill_perms(user):'
166 #===========================================================================
169 #===========================================================================
167 # fetch default permissions
170 # fetch default permissions
168 #===========================================================================
171 #===========================================================================
172 default_user = sa.query(User)\
173 .options(FromCache('sql_cache_short','getuser_%s' % 'default'))\
174 .filter(User.username == 'default').scalar()
175
169 default_perms = sa.query(RepoToPerm, Repository, Permission)\
176 default_perms = sa.query(RepoToPerm, Repository, Permission)\
170 .join((Repository, RepoToPerm.repository_id == Repository.repo_id))\
177 .join((Repository, RepoToPerm.repository_id == Repository.repo_id))\
171 .join((Permission, RepoToPerm.permission_id == Permission.permission_id))\
178 .join((Permission, RepoToPerm.permission_id == Permission.permission_id))\
172 .filter(RepoToPerm.user == sa.query(User).filter(User.username ==
179 .filter(RepoToPerm.user == default_user).all()
173 'default').scalar()).all()
174
180
175 if user.is_admin:
181 if user.is_admin:
176 #=======================================================================
182 #=======================================================================
@@ -18,9 +18,11 b" The rest of what's here are standard SQL"
18 Beaker constructs.
18 Beaker constructs.
19
19
20 """
20 """
21 from beaker.exceptions import BeakerException
21 from sqlalchemy.orm.interfaces import MapperOption
22 from sqlalchemy.orm.interfaces import MapperOption
22 from sqlalchemy.orm.query import Query
23 from sqlalchemy.orm.query import Query
23 from sqlalchemy.sql import visitors
24 from sqlalchemy.sql import visitors
25 import beaker
24
26
25 class CachingQuery(Query):
27 class CachingQuery(Query):
26 """A Query subclass which optionally loads full results from a Beaker
28 """A Query subclass which optionally loads full results from a Beaker
@@ -105,7 +107,13 b' def query_callable(manager):'
105 def query(*arg, **kw):
107 def query(*arg, **kw):
106 return CachingQuery(manager, *arg, **kw)
108 return CachingQuery(manager, *arg, **kw)
107 return query
109 return query
108
110
111 def get_cache_region(name, region):
112 if region not in beaker.cache.cache_regions:
113 raise BeakerException('Cache region not configured: %s' % region)
114 kw = beaker.cache.cache_regions[region]
115 return beaker.cache.Cache._get_cache(name, kw)
116
109 def _get_cache_parameters(query):
117 def _get_cache_parameters(query):
110 """For a query with cache_region and cache_namespace configured,
118 """For a query with cache_region and cache_namespace configured,
111 return the correspoinding Cache instance and cache key, based
119 return the correspoinding Cache instance and cache key, based
@@ -125,8 +133,8 b' def _get_cache_parameters(query):'
125 cache_key = " ".join([str(x) for x in args])
133 cache_key = " ".join([str(x) for x in args])
126
134
127 # get cache
135 # get cache
128 cache = query.cache_manager.get_cache_region(namespace, region)
136 #cache = query.cache_manager.get_cache_region(namespace, region)
129
137 cache = get_cache_region(namespace, region)
130 # optional - hash the cache_key too for consistent length
138 # optional - hash the cache_key too for consistent length
131 # import uuid
139 # import uuid
132 # cache_key= str(uuid.uuid5(uuid.NAMESPACE_DNS, cache_key))
140 # cache_key= str(uuid.uuid5(uuid.NAMESPACE_DNS, cache_key))
@@ -28,36 +28,6 b' Base = declarative_base()'
28 #===============================================================================
28 #===============================================================================
29 # CACHE OPTIONS
29 # CACHE OPTIONS
30 #===============================================================================
30 #===============================================================================
31 cache_base = jn(dn(dn(dn(abspath(__file__)))), 'data')
31 #Configured globally in .ini files
32 cache_dir = jn(cache_base, 'cache')
33
34 if not os.path.isdir(cache_base):
35 os.mkdir(cache_base)
36
37 if not os.path.isdir(cache_dir):
38 os.mkdir(cache_dir)
39 # set start_time to current time
40 # to re-cache everything
41 # upon application startup
42 start_time = time.time()
43 # configure the "sqlalchemy" cache region.
44 cache_manager.regions['sql_cache_short'] = {
45 'type':'memory',
46 'data_dir':cache_dir,
47 'expire':10,
48 'start_time':start_time
49 }
50 cache_manager.regions['sql_cache_med'] = {
51 'type':'memory',
52 'data_dir':cache_dir,
53 'expire':360,
54 'start_time':start_time
55 }
56 cache_manager.regions['sql_cache_long'] = {
57 'type':'file',
58 'data_dir':cache_dir,
59 'expire':3600,
60 'start_time':start_time
61 }
62 #to use cache use this in query
32 #to use cache use this in query
63 #.options(FromCache("sqlalchemy_cache_type", "cachekey"))
33 #.options(FromCache("sqlalchemy_cache_type", "cachekey"))
General Comments 0
You need to be logged in to leave comments. Login now