本文整理汇总了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")