Repository URL to install this package:
|
Version:
0.0.1 ▾
|
import datetime
from django.core.cache import cache
from django.utils.encoding import force_text
from rest_framework_extensions.key_constructor.bits import (
KeyBitBase,
ListSqlQueryKeyBit,
PaginationKeyBit)
from rest_framework_extensions.key_constructor.constructors import (
DefaultKeyConstructor
)
class UpdatedAtKeyBit(KeyBitBase):
def __init__(self, key, *args, **kwargs):
assert key
super().__init__(*args, **kwargs)
self.key = key
def get_data(self, **kwargs):
value = cache.get(self.key, None)
if not value:
value = datetime.datetime.utcnow()
cache.set(self.key, value=value)
return force_text(value)
def list_cache_update_invalidator_factory(key):
class UpdateInvalidatorListKeyConstructor(DefaultKeyConstructor):
list_sql = ListSqlQueryKeyBit()
pagination = PaginationKeyBit()
updated_at = UpdatedAtKeyBit(key)
return UpdateInvalidatorListKeyConstructor