本文整理匯總了Python中django.core.cache.cache.incr方法的典型用法代碼示例。如果您正苦於以下問題:Python cache.incr方法的具體用法?Python cache.incr怎麽用?Python cache.incr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.core.cache.cache
的用法示例。
在下文中一共展示了cache.incr方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _safe_cache_incr
# 需要導入模塊: from django.core.cache import cache [as 別名]
# 或者: from django.core.cache.cache import incr [as 別名]
def _safe_cache_incr(self):
""" cache.incr that silently handles down cache """
return self._down_cache_handler_partial()(cache.incr)
示例2: new_email
# 需要導入模塊: from django.core.cache import cache [as 別名]
# 或者: from django.core.cache.cache import incr [as 別名]
def new_email():
cache.add('error_email_throttle', 0, settings.DMOJ_EMAIL_THROTTLING[1])
return cache.incr('error_email_throttle')
示例3: observer_evaluate
# 需要導入模塊: from django.core.cache import cache [as 別名]
# 或者: from django.core.cache.cache import incr [as 別名]
def observer_evaluate(self, message):
"""Execute observer evaluation on the worker or throttle."""
observer_id = message['observer']
throttle_rate = get_queryobserver_settings()['throttle_rate']
if throttle_rate <= 0:
await self._evaluate(observer_id)
return
cache_key = throttle_cache_key(observer_id)
try:
count = cache.incr(cache_key)
# Ignore if delayed observer already scheduled.
if count == 2:
await self.channel_layer.send(
CHANNEL_MAIN,
{
'type': TYPE_POLL,
'observer': observer_id,
'interval': throttle_rate,
},
)
except ValueError:
count = cache.get_or_set(cache_key, default=1, timeout=throttle_rate)
# Ignore if cache was set and increased in another thread.
if count == 1:
await self._evaluate(observer_id)
示例4: increment_cache_key
# 需要導入模塊: from django.core.cache import cache [as 別名]
# 或者: from django.core.cache.cache import incr [as 別名]
def increment_cache_key(cache_key):
try:
cache.incr(cache_key)
except ValueError:
cache.set(cache_key, 1, None)
示例5: test_incr
# 需要導入模塊: from django.core.cache import cache [as 別名]
# 或者: from django.core.cache.cache import incr [as 別名]
def test_incr(self):
# Cache values can be incremented
cache.set("answer", 41)
assert cache.incr("answer") == 42
assert cache.get("answer") == 42
assert cache.incr("answer", 10) == 52
assert cache.get("answer") == 52
assert cache.incr("answer", -10) == 42
with pytest.raises(ValueError):
cache.incr("does_not_exist")
示例6: test_cache_versioning_incr_decr
# 需要導入模塊: from django.core.cache import cache [as 別名]
# 或者: from django.core.cache.cache import incr [as 別名]
def test_cache_versioning_incr_decr(self):
cache.set("answer1", 37, version=1)
cache.set("answer1", 42, version=2)
cache.incr("answer1")
assert cache.get("answer1", version=1) == 38
assert cache.get("answer1", version=2) == 42
cache.decr("answer1")
assert cache.get("answer1", version=1) == 37
assert cache.get("answer1", version=2) == 42
cache.set("answer2", 37, version=1)
cache.set("answer2", 42, version=2)
cache.incr("answer2", version=2)
assert cache.get("answer2", version=1) == 37
assert cache.get("answer2", version=2) == 43
cache.decr("answer2", version=2)
assert cache.get("answer2", version=1) == 37
assert cache.get("answer2", version=2) == 42
cache.set("answer3", 37, version=1)
cache.set("answer3", 42, version=2)
caches["v2"].incr("answer3")
assert cache.get("answer3", version=1) == 37
assert cache.get("answer3", version=2) == 43
caches["v2"].decr("answer3")
assert cache.get("answer3", version=1) == 37
assert cache.get("answer3", version=2) == 42
cache.set("answer4", 37, version=1)
cache.set("answer4", 42, version=2)
caches["v2"].incr("answer4", version=1)
assert cache.get("answer4", version=1) == 38
assert cache.get("answer4", version=2) == 42
caches["v2"].decr("answer4", version=1)
assert cache.get("answer4", version=1) == 37
assert cache.get("answer4", version=2) == 42
示例7: test_incr_range
# 需要導入模塊: from django.core.cache import cache [as 別名]
# 或者: from django.core.cache.cache import incr [as 別名]
def test_incr_range(self):
cache.set("overwhelm", BIGINT_SIGNED_MAX - 1)
cache.incr("overwhelm")
with pytest.raises(IntegrityError):
cache.incr("overwhelm")
示例8: test_cant_incr_decimals
# 需要導入模塊: from django.core.cache import cache [as 別名]
# 或者: from django.core.cache.cache import incr [as 別名]
def test_cant_incr_decimals(self):
# Cached values that aren't ints can't be incremented
cache.set("answer", Decimal("1.1"))
with pytest.raises(ValueError):
cache.incr("answer")
示例9: test_set_int_subclass
# 需要導入模塊: from django.core.cache import cache [as 別名]
# 或者: from django.core.cache.cache import incr [as 別名]
def test_set_int_subclass(self):
# Storing an int subclass should return that int subclass
cache.set("myint", MyInt(2))
val = cache.get("myint")
assert val.times2() == 4
# Can't increment it since it's a pickle object on the table, not an
# integer
with pytest.raises(ValueError):
cache.incr("myint")