def __init__(self, indexer, user, acl_mapping): """ This object is created at the start of a transaction. It is accessed via flaskg.storage. :param indexer: indexing middleware instance :param user: a User instance (used for checking permissions) :param acl_mapping: list of (name_prefix, acls) tuples, longest prefix first, '' last acls = dict with before, default, after, hierarchic entries """ self.indexer = indexer self.user = user self.acl_mapping = acl_mapping self.valid_rights = ACL_RIGHTS_CONTENTS # The ProtectingMiddleware exists just 1 request long, but might have # to parse and evaluate huge amounts of ACLs. We avoid doing same stuff # again and again by using some fresh lru caches for each PMW instance. lru_cache_decorator = lru_cache(PARSE_CACHE) self.parse_acl = lru_cache_decorator(self._parse_acl) lru_cache_decorator = lru_cache(EVAL_CACHE) self.eval_acl = lru_cache_decorator(self._eval_acl) lru_cache_decorator = lru_cache(LOOKUP_CACHE) self.get_acls = lru_cache_decorator(self._get_acls) lru_cache_decorator = lru_cache(ACL_CACHE) self.allows = lru_cache_decorator(self._allows) # placeholder to show we are passing meta data around without affecting lru caches self.meta = None
def __init__(self, indexer, user, acl_mapping): """ :param indexer: indexing middleware instance :param user: a User instance (used for checking permissions) :param acl_mapping: list of (name_prefix, acls) tuples, longest prefix first, '' last acls = dict with before, default, after, hierarchic entries """ self.indexer = indexer self.user = user self.acl_mapping = acl_mapping self.valid_rights = ACL_RIGHTS_CONTENTS # The ProtectingMiddleware exists just 1 request long, but might have # to parse and evaluate huge amounts of ACLs. We avoid doing same stuff # again and again by using some fresh lru caches for each PMW instance. lru_cache_decorator = lru_cache(PARSE_CACHE) self.parse_acl = lru_cache_decorator(self._parse_acl) lru_cache_decorator = lru_cache(EVAL_CACHE) self.eval_acl = lru_cache_decorator(self._eval_acl) lru_cache_decorator = lru_cache(LOOKUP_CACHE) self.get_acls = lru_cache_decorator(self._get_acls)
def clear(self): if self.lang: from whoosh.lang import stemmer_for_language stemfn = stemmer_for_language(self.lang) else: stemfn = self.stemfn if isinstance(self.cachesize, integer_types) and self.cachesize != 0: if self.cachesize < 0: self._stem = unbound_cache(stemfn) elif self.cachesize > 1: self._stem = lru_cache(self.cachesize)(stemfn) else: self._stem = stemfn