diff options
author | Jason Kirtland <jek@discorporate.us> | 2008-04-02 11:39:26 +0000 |
---|---|---|
committer | Jason Kirtland <jek@discorporate.us> | 2008-04-02 11:39:26 +0000 |
commit | f12969a4d8dd8a4f91a9da4cc9d855457a5a0060 (patch) | |
tree | 274125cdcd73dbcea79575b7a82810032ae0be36 /lib/sqlalchemy/engine/base.py | |
parent | a0000075437370ae23d0db48c706a4237f4e43f3 (diff) | |
download | sqlalchemy-f12969a4d8dd8a4f91a9da4cc9d855457a5a0060.tar.gz |
- Revamped the Connection memoize decorator a bit, moved to engine
- MySQL character set caching is more aggressive but will invalidate the cache if a SET is issued.
- MySQL connection memos are namespaced: info[('mysql', 'server_variable')]
Diffstat (limited to 'lib/sqlalchemy/engine/base.py')
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 3d7e65198..cd662ac92 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -12,7 +12,7 @@ higher-level statement-construction, connection-management, execution and result contexts. """ -import StringIO, sys +import inspect, StringIO, sys from sqlalchemy import exceptions, schema, util, types, logging from sqlalchemy.sql import expression @@ -1864,3 +1864,27 @@ class DefaultRunner(schema.SchemaVisitor): return default.arg(self.context) else: return default.arg + + +def connection_memoize(key): + """Decorator, memoize a function in a connection.info stash. + + Only applicable to functions which take no arguments other than a + connection. The memo will be stored in ``connection.info[key]``. + + """ + def decorate(fn): + spec = inspect.getargspec(fn) + assert len(spec[0]) == 2 + assert spec[0][1] == 'connection' + assert spec[1:3] == (None, None) + + def decorated(self, connection): + try: + return connection.info[key] + except KeyError: + connection.info[key] = val = fn(self, connection) + return val + + return util.function_named(decorated, fn.__name__) + return decorate |