wheezy.web / demos / template / src / membership / repository / caching.py

"""
"""

from wheezy.caching import CacheDependency

from config import cache_factory
from membership.repository import keys
from membership.repository.contract import IMembershipRepository


class MembershipRepository(IMembershipRepository):

    def __init__(self, inner):
        self.inner = inner

    def authenticate(self, credential):
        # TODO:
        return self.inner.authenticate(credential)

    def has_account(self, username):
        key = keys.has_account(username)
        #with cache_factory() as c:
        c = cache_factory()
        try:
            c.__enter__()
            result = c.get(key)
        finally:
            c.__exit__(None, None, None)
        if result is None:
            result = self.inner.has_account(username)
            if result is not None:
                #with cache_factory() as c:
                c = cache_factory()
                try:
                    c.__enter__()
                    c.set(key, result, time=600, namespace='membership')
                finally:
                    c.__exit__(None, None, None)
        return result

    def user_roles(self, username):
        # TODO:
        return self.inner.user_roles(username)

    def create_account(self, registration):
        key = keys.has_account(registration.credential.username)
        #with cache_factory() as c:
        c = cache_factory()
        try:
            c.__enter__()
            c.delete(key, namespace='membership')
        finally:
            c.__exit__(None, None, None)
        return self.inner.create_account(registration)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.