Commits

Lynn Rees committed 701a699

[svn]

Comments (0)

Files changed (5)

branches/0.3/trunk/wsgistate/db.py

     raise ImportError('DbCache module requires the SQLAlchemy package ' \
         'from http://www.sqlalchemy.org/')
 from wsgistate.base import BaseCache
+from wsgistate.cache import WsgiMemoize
+from wsgistate.session import CookieSession, URLSession, SessionCache
 
-__all__ = ['DbCache']
+__all__ = ['DbCache', 'memoize', 'session', 'urlsession']
+
+
+def memoize(initstr, **kw):
+    '''Decorator for caching.
+
+    @param initstr Database initialization string
+    '''
+    def decorator(application):
+        _db_memo_cache = DbCache(initstr, **kw)
+        return WsgiMemoize(application, _db_memo_cache, **kw)
+    return decorator
+
+def session(initstr, **kw):
+    '''Decorator for sessions.
+
+    @param initstr Database initialization string
+    '''
+    def decorator(application):
+        _db_base_cache = DbCache(initstr, **kw)
+        _db_session_cache = SessionCache(_db_base_cache, **kw)
+        return CookieSession(application, _db_session_cache, **kw)
+    return decorator
+
+def urlsession(initstr, **kw):
+    '''Decorator for URL encoded sessions.
+
+    @param initstr Database initialization string
+    '''
+    def decorator(application):
+        _db_ubase_cache = DbCache(initstr, **kw)
+        _db_url_cache = SessionCache(_db_ubase_cache, **kw)
+        return URLSession(application, _db_url_cache, **kw)
+    return decorator
 
 
 class DbCache(BaseCache):     

branches/0.3/trunk/wsgistate/file.py

 except ImportError:
     import pickle
 from wsgistate.simple import SimpleCache
+from wsgistate.cache import WsgiMemoize
+from wsgistate.session import CookieSession, URLSession, SessionCache
 
-__all__ = ['FileCache']
+__all__ = ['FileCache', 'memoize', 'session', 'urlsession']
+
+
+def memoize(path, **kw):
+    '''Decorator for caching.
+
+    @param path Filesystem path
+    '''
+    def decorator(application):
+        _file_memo_cache = FileCache(path, **kw)
+        return WsgiMemoize(application, _file_memo_cache, **kw)
+    return decorator
+
+def session(path, **kw):
+    '''Decorator for sessions.
+
+    @param path Filesystem path
+    '''
+    def decorator(application):
+        _file_base_cache = FileCache(path, **kw)
+        _file_session_cache = SessionCache(_file_base_cache, **kw)
+        return CookieSession(application, _file_session_cache, **kw)
+    return decorator
+
+def urlsession(path, **kw):
+    '''Decorator for URL encoded sessions.
+
+    @param path Filesystem path
+    '''
+    def decorator(application):
+        _file_ubase_cache = FileCache(path, **kw)
+        _file_url_cache = SessionCache(_file_ubase_cache, **kw)
+        return URLSession(application, _file_url_cache, **kw)
+    return decorator
 
 
 class FileCache(SimpleCache):

branches/0.3/trunk/wsgistate/memcached.py

 except ImportError:
     raise ImportError("Memcached cache backend requires the 'memcache' library")
 from wsgistate.base import BaseCache
+from wsgistate.cache import WsgiMemoize
+from wsgistate.session import CookieSession, URLSession, SessionCache
 
-__all__ = ['MemCached']
+__all__ = ['MemCached', 'memoize', 'session', 'urlsession']
+
+
+def memoize(path, **kw):
+    '''Decorator for caching.
+
+    @param path Client path
+    '''
+    def decorator(application):
+        _mc_memo_cache = MemCached(path, **kw)
+        return WsgiMemoize(application, _mc_memo_cache, **kw)
+    return decorator
+
+def session(path, **kw):
+    '''Decorator for sessions.
+
+    @param path Client path
+    '''
+    def decorator(application):
+        _mc_base_cache = MemCached(path, **kw)
+        _mc_session_cache = SessionCache(_mc_base_cache, **kw)
+        return CookieSession(application, _mc_session_cache, **kw)
+    return decorator
+
+def urlsession(path, **kw):
+    '''Decorator for URL encoded sessions.
+
+    @param path Client path
+    '''
+    def decorator(application):
+        _mc_ubase_cache = MemCached(path, **kw)
+        _mc_url_cache = SessionCache(_mc_ubase_cache, **kw)
+        return URLSession(application, _mc_url_cache, **kw)
+    return decorator
 
 
 class MemCached(BaseCache):

branches/0.3/trunk/wsgistate/memory.py

 except ImportError:
     import dummy_threading as threading
 from wsgistate.simple import SimpleCache
+from wsgistate.cache import WsgiMemoize
+from wsgistate.session import CookieSession, URLSession, SessionCache
 
-__all__ = ['MemoryCache']
+__all__ = ['MemoryCache', 'memoize', 'session', 'urlsession']
+
+def memoize(**kw):
+    '''Decorator for caching.'''
+    def decorator(application):
+        _mem_memo_cache = MemoryCache(**kw)
+        return WsgiMemoize(application, _mem_memo_cache, **kw)
+    return decorator
+
+def session(**kw):
+    '''Decorator for sessions.'''
+    def decorator(application):
+        _mem_base_cache = MemoryCache(**kw)
+        _mem_session_cache = SessionCache(_mem_base_cache, **kw)
+        return CookieSession(application, _mem_session_cache, **kw)
+    return decorator
+
+def urlsession(**kw):
+    '''Decorator for URL encoded sessions.'''
+    def decorator(application):
+        _mem_ubase_cache = MemoryCache(**kw)
+        _mem_url_cache = SessionCache(_mem_ubase_cache, **kw)
+        return URLSession(application, _mem_url_cache, **kw)
+    return decorator
+
 
 class MemoryCache(SimpleCache):
 

branches/0.3/trunk/wsgistate/simple.py

 
 import time
 from wsgistate.base import BaseCache
+from wsgistate.cache import WsgiMemoize
+from wsgistate.session import CookieSession, URLSession, SessionCache
 
-__all__ = ['SimpleCache']
+__all__ = ['SimpleCache', 'memoize', 'session', 'urlsession']
+
+def memoize(**kw):
+    '''Decorator for caching.'''
+    def decorator(application):
+        _simple_memo_cache = SimpleCache(**kw)
+        return WsgiMemoize(application, _simple_memo_cache, **kw)
+    return decorator
+
+def session(**kw):
+    '''Decorator for sessions.'''
+    def decorator(application):
+        _simple_base_cache = SimpleCache(**kw)
+        _simple_session_cache = SessionCache(_simple_base_cache, **kw)
+        return CookieSession(application, _simple_session_cache, **kw)
+    return decorator
+
+def urlsession(**kw):
+    '''Decorator for URL encoded sessions.'''
+    def decorator(application):
+        _simple_ubase_cache = SimpleCache(**kw)
+        _simple_url_cache = SessionCache(_simple_ubase_cache, **kw)
+        return URLSession(application, _simple_url_cache, **kw)
+    return decorator
 
 
 class SimpleCache(BaseCache):