Permalink
Browse files

Making the memcache connection be cached in threadlocal storage

  • Loading branch information...
1 parent abb6af3 commit 1670f24788bc05ac07fd22717c0c021ae4375602 Jason Baker committed Aug 30, 2010
Showing with 6 additions and 3 deletions.
  1. +6 −3 shrapnel/config.py
View
@@ -165,13 +165,16 @@ def __defaults__(self):
provider = 'no_provider_defined'
)
-
+_client_data = threading.local()
class MemcacheProvider(InstanceProvider, Provider):
__abstract__ = True
def construct(self, config):
- import memcache
- return memcache.Client(["%s:%d" % (config['host'], config['port'])], debug=config['debug'])
+ global _client_data
+ if not hasattr(_client_data, 'conn'):
+ import memcache
+ _client_data.conn = memcache.Client(["%s:%d" % (config['host'], config['port'])], debug=config['debug'])
+ return _client_data.conn
def __defaults__(self):
return dict(

0 comments on commit 1670f24

Please sign in to comment.