def test_request_cached_property(): class Foo(object): @request_cached_property def bar(self): return 5 name = __name__ + '.bar' foo = Foo() assert threadlocal.get(name) is None assert 5 == foo.bar assert 5 == threadlocal.get(name) threadlocal.set(name, 6) assert 6 == foo.bar assert 6 == Foo().bar # cache is shared between instances
def _init(self, session, raise_errors): self.session = session self.raise_errors = raise_errors self.results = { 'running': True, 'completed': False, 'categories': defaultdict(lambda: defaultdict(int)) } # note: this will get cleared after request_cached_context object is released. assert not threadlocal.get('currently_running_email_daemon') threadlocal.set('currently_running_email_daemon', self)
def poll(self): """empty method which exists only to help keep WebSockets alive""" log.debug('sideboard.poll by user {}', threadlocal.get('username'))
def index(self): return threadlocal.get('username')
def _currently_running_daemon_on_this_thread(cls): return threadlocal.get('currently_running_email_daemon')
def with_caching(self): val = threadlocal.get(name) if val is None: val = func(self) threadlocal.set(name, val) return val