def test_cache_validation(self): """cache correctly validates""" version = cachebuster.get_version(self.cache_name) self.assertEqual(version, 0) db_version = CacheVersion.objects.get(cache=self.cache_name).version self.assertEqual(db_version, 0) self.assertEqual(db_version, version) self.assertTrue(cachebuster.is_valid(self.cache_name, version)) self.assertTrue(cachebuster.is_valid(self.cache_name, db_version))
def test_cache_invalidation(self): """invalidate has increased valid version number""" db_version = CacheVersion.objects.get(cache=self.cache_name).version cachebuster.invalidate(self.cache_name) new_version = cachebuster.get_version(self.cache_name) new_db_version = CacheVersion.objects.get(cache=self.cache_name) new_db_version = new_db_version.version self.assertEqual(new_version, 1) self.assertEqual(new_db_version, 1) self.assertEqual(new_version, new_db_version) self.assertFalse(cachebuster.is_valid(self.cache_name, db_version)) self.assertTrue(cachebuster.is_valid(self.cache_name, new_db_version))
def is_valid(self): version_is_valid = cachebuster.is_valid(BAN_CACHEBUSTER, self.bans_version) date_today = timezone.now().date() not_expired = not self.valid_until or self.valid_until > date_today return version_is_valid and not_expired
def _get_session_bancache(request): try: ban_cache = request.session[CACHE_SESSION_KEY] ban_cache = _hydrate_session_cache(ban_cache) if ban_cache['ip'] != request.user_ip: return None if not cachebuster.is_valid(VERSION_KEY, ban_cache['version']): return None if ban_cache.get('expires_on'): if ban_cache['expires_on'] < timezone.today(): return None return ban_cache except KeyError: return None
def _get_session_bancache(request): try: ban_cache = request.session[BAN_CACHE_SESSION_KEY] ban_cache = _hydrate_session_cache(ban_cache) if ban_cache['ip'] != request._misago_real_ip: return None if not cachebuster.is_valid(BAN_VERSION_KEY, ban_cache['version']): return None if ban_cache.get('valid_until'): """ Make two timezone unaware dates and compare them """ if ban_cache.get('valid_until') < date.today(): return None return ban_cache except KeyError: return None
def _get_session_bancache(request): try: ban_cache = request.session[BAN_CACHE_SESSION_KEY] ban_cache = _hydrate_session_cache(ban_cache) if ban_cache['ip'] != request._misago_real_ip: return None if not cachebuster.is_valid(BAN_VERSION_KEY, ban_cache['version']): return None if ban_cache.get('expires_on'): """ Hydrate ban date """ if ban_cache['expires_on'] < timezone.today(): return None return ban_cache except KeyError: return None
def _get_session_bancache(request): try: ban_cache = request.session[BAN_CACHE_SESSION_KEY] ban_cache = _hydrate_session_cache(ban_cache) if ban_cache["ip"] != request.user_ip: return None if not cachebuster.is_valid(BAN_VERSION_KEY, ban_cache["version"]): return None if ban_cache.get("expires_on"): """ Hydrate ban date """ if ban_cache["expires_on"] < timezone.today(): return None return ban_cache except KeyError: return None
def is_valid(version): return cachebuster.is_valid(ACL_CACHEBUSTER, version)
def is_valid(self): version_is_valid = cachebuster.is_valid(BAN_CACHEBUSTER, self.bans_version) expired = self.expires_on and self.expires_on < timezone.now() return version_is_valid and not expired
def is_valid(version): return cb.is_valid(ACL_CACHE_NAME, version)