У меня есть следующий класс:
class Account(db.Model):
__tablename__ = 'accounts'
__versioned__ = {
'exclude': ['VPSs']
}
id = db.Column(db.Integer, primary_key=True)
def __repr__(self):
return "%s(%s)" % (self.__class__.__name__, self.id)
@property
@cache.memoize(timeout=86400)
def days_to_topup(self):
"""Rather than using inline model form, just reflect this
"""
return self.vendor.days_to_topup
У меня было чувство, что я вообще не работаю с кэшем. Поэтому я добавил в свой библиотечный файл следующее:
def get(self, key):
try:
expires, value = self._cache[key]
if expires == 0 or expires > time():
return pickle.loads(value)
except (KeyError, pickle.PickleError):
print("Key missing: %s" % key)
return None
Когда я впервые получил доступ к этому методу, я увидел следующее, напечатанное на моей консоли:
Key missing: portal.account.models.Account.days_to_topup.Account25_memver
Key missing: pAZujNOzo2JX6Tz6T4O3UdS7nzAw
Key missing: portal.account.models.Account.days_to_topup.Account24_memver
Key missing: s3GWC1YnjUGIW/QDT4O3UdwsxOfQ
Key missing: HHb45l3zEGDTepyCT4O3UdTninm7
Key missing: portal.account.models.Account.days_to_topup.Account20_memver
Key missing: tW0ezIHoB3mRHHd4T4O3UduywXbT
Key missing: portal.account.models.Account.days_to_topup.Account19_memver
Key missing: 73KXuVicSsFECnXcT4O3UdDYt/2Z
...
И тогда я решил снова обратиться к этому методу, я понял, что вижу тот же «Ключ отсутствует»:
Key missing: portal.account.models.Account.days_to_topup.Account25_memver
Key missing: pAZujNOzo2JX6Tz6njTvFgk2N2jF
Key missing: portal.account.models.Account.days_to_topup.Account24_memver
Key missing: s3GWC1YnjUGIW/QDnjTvFg2r/Ip2
Key missing: portal.account.models.Account.days_to_topup.Account22_memver
Key missing: HHb45l3zEGDTepyCnjTvFgU/EEE6
Key missing: portal.account.models.Account.days_to_topup.Account20_memver
Key missing: tW0ezIHoB3mRHHd4njTvFgQpKev8
Key missing: portal.account.models.Account.days_to_topup.Account19_memver
Так что я не понимаю, почему @ cache.memoization не работает так, как задумано.
Сначала я подумал, что это потому, что переменная self
продолжала изменяться, но это не имело бы смысла, так как я repr определил
Почему я все время пропускаю свой кеш?