本文整理汇总了Python中r2.lib.memoize.clear_memo函数的典型用法代码示例。如果您正苦于以下问题:Python clear_memo函数的具体用法?Python clear_memo怎么用?Python clear_memo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了clear_memo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _new
def _new(cls, author, link, parent, body, ip, spam = False):
c = Comment(body = body,
link_id = link._id,
sr_id = link.sr_id,
author_id = author._id,
ip = ip)
c._spam = spam
#these props aren't relations
if parent:
c.parent_id = parent._id
c._commit()
link._incr('num_comments', 1)
if parent:
to = Account._byID(parent.author_id)
i = Inbox._add(to, c, 'inbox')
#clear that chache
clear_memo('builder.link_comments2', link._id)
from admintools import admintools
utils.worker.do(lambda: admintools.add_thing(c))
return c
示例2: _submit
def _submit(cls, title, url, author, sr, ip, spam = False):
from admintools import admintools
if url != u'self':
try:
l = Link._by_url(url, sr)
raise LinkExists
except NotFound:
pass
l = cls(title = title,
url = url,
_spam = spam,
author_id = author._id,
sr_id = sr._id,
lang = sr.lang,
ip = ip)
l._commit()
clear_memo('link._by_url', Link, url, sr)
# clear cache for lookups without sr
clear_memo('link._by_url', Link, url, None)
utils.worker.do(lambda: admintools.add_thing(l))
return l
示例3: clear_account_by_name_cache
def clear_account_by_name_cache():
q = Account._query(Account.c._deleted == (True, False), data = True)
for account in q:
name = account.name
clear_memo('account._by_name', Account, name.lower(), True)
clear_memo('account._by_name', Account, name.lower(), False)
print "Cleared cache for %s" % account.name
示例4: set_amount
def set_amount(cls, r, amount):
old_amount = int(r._name)
if old_amount != amount:
r._name = str(amount)
r._commit()
#update the cache for the amount = 0 and amount = None cases
rel = cls.rels[(r._thing1.__class__, r._thing2.__class__)]
for a in set((old_amount, amount, None)):
# clear memoizing around this thing's author
if not r._thing2._loaded: r._thing2._load()
if hasattr(r._thing2, "author_id"):
clear_memo('report._by_author', cls, r._thing2.author_id,
amount = a)
for t in (r._thing1, r._thing2):
thing_key = cls._cache_prefix(rel, t.__class__,
amount = a) + str(t._id)
v = cache.get(thing_key)
if v is not None:
if a == old_amount and old_amount != amount and r._id in v:
v.remove(r._id)
elif r._id not in v:
v.append(r._id)
cache.set(thing_key, v)
示例5: _new
def _new(cls, author, link, parent, body, ip, spam = False):
c = Comment(body = body,
link_id = link._id,
sr_id = link.sr_id,
author_id = author._id,
ip = ip)
c._spam = spam
#these props aren't relations
if parent:
c.parent_id = parent._id
c._commit()
link._incr('num_comments', 1)
inbox_rel = None
if parent:
to = Account._byID(parent.author_id)
# only global admins can be message spammed.
if not c._spam or to.name in g.admins:
inbox_rel = Inbox._add(to, c, 'inbox')
#clear that chache
clear_memo('builder.link_comments2', link._id)
return (c, inbox_rel)
示例6: register
def register(name, password, email):
try:
a = Account._by_name(name)
raise AccountExists
except NotFound:
a = Account(name = name,
password = passhash(name, password, True))
a.email = email
a.confirmation_code = random_key(6)
a.email_validated = False
a.wiki_account = '__error__'
a._commit()
from r2.lib import emailer
emailer.confirmation_email(a)
if wiki_account.valid_name(name):
def send_wiki_failed_email():
emailer.wiki_failed_email(a)
a.create_associated_wiki_account(password,
on_request_error=send_wiki_failed_email)
else:
emailer.wiki_incompatible_name_email(a)
# Clear memoization of both with and without deleted
clear_memo('account._by_name', Account, name.lower(), True)
clear_memo('account._by_name', Account, name.lower(), False)
return a
示例7: userrel_remove
def userrel_remove(self, user):
fn = getattr(self, exists_name)
s = fn(user)
if s:
s._delete()
clear_memo(all_memo_str, self)
clear_memo(reverse_memo_str, user)
return True
示例8: userrel_add
def userrel_add(self, user):
fn = getattr(self, exists_name)
if not fn(user):
s = relation(self, user, name)
s._commit()
clear_memo(all_memo_str, self)
clear_memo(reverse_memo_str, user)
return s
示例9: delete
def delete(self):
self._deleted = True
self._commit()
clear_memo("account._by_name", Account, self.name.lower(), False)
# remove from friends lists
q = Friend._query(Friend.c._thing2_id == self._id, Friend.c._name == "friend", eager_load=True)
for f in q:
f._thing1.remove_friend(f._thing2)
示例10: _new
def _new(self, name, title, lang="en", type="public", over_18=False, **kw):
try:
sr = Subreddit._by_name(name)
raise SubredditExists
except NotFound:
sr = Subreddit(name=name, title=title, lang=lang, type=type, over_18=over_18, **kw)
sr._commit()
clear_memo("subreddit._by_name", Subreddit, name.lower())
clear_memo("subreddit.subreddits", Subreddit)
return sr
示例11: _new
def _new(self, name, **kw):
tag_name = name.lower()
try:
tag = Tag._by_name(tag_name)
raise TagExists
except NotFound:
tag = Tag(name = tag_name, **kw)
tag._commit()
clear_memo('tag._by_name', Tag, name.lower())
return tag
示例12: register
def register(name, password):
try:
a = Account._by_name(name)
raise AccountExists
except NotFound:
a = Account(name = name,
password = passhash(name, password, True))
a._commit()
clear_memo('account._by_name', Account, name.lower(), False)
return a
示例13: register
def register(name, password):
try:
a = Account._by_name(name)
raise AccountExists
except NotFound:
a = Account(name = name,
password = passhash(name, password, True))
a._commit()
# Clear memoization of both with and without deleted
clear_memo('account._by_name', Account, name.lower(), True)
clear_memo('account._by_name', Account, name.lower(), False)
return a
示例14: opt_in
def opt_in(self, msg_hash):
"""Removes recipient of the email from the opt-out list"""
email = self.get_recipient(msg_hash)
if email:
o = self.opt_table
if self.has_opted_out(email):
sa.delete(o, o.c.email == email).execute()
clear_memo('r2.models.mail_queue.has_opted_out',
email)
clear_memo('r2.models.mail_queue.opt_count')
return (email, True)
else:
return (email, False)
return (None, False)
示例15: opt_out
def opt_out(self, msg_hash):
"""Adds the recipient of the email to the opt-out list and returns
that address."""
email = self.get_recipient(msg_hash)
if email:
o = self.opt_table
try:
o.insert().execute({o.c.email: email, o.c.msg_hash: msg_hash})
clear_memo('r2.models.mail_queue.has_opted_out',
email)
clear_memo('r2.models.mail_queue.opt_count')
return (email, True)
except sa.exceptions.SQLError:
return (email, False)
return (None, False)