def test_get_exists(self): """Test that the value is returned if a key has been saved.""" CacheService.set_value_for_key('fake_key', 'fake_value') self.assertEquals( CacheService.fetch_value_for_key('fake_key'), 'fake_value', )
def _mark_hash_seen(self, data_hash): """Adds the data hash to the cache. :param str data_hash: hash to store """ CacheService.set_value_for_key( self._get_cache_key(data_hash), data_hash, )
def test_ttl(self): """Test that a key can expire.""" with freeze_time('2014-01-01T00:00:00'): CacheService.set_value_for_key('fake_key', 'fake_value', ttl=5) self.assertEquals( CacheService.fetch_value_for_key('fake_key'), 'fake_value', ) with freeze_time('2014-01-01T00:00:06'): self.assertIsNone(CacheService.fetch_value_for_key('fake_key'), )
def test_ttl(self): """Test that a key can expire.""" with freeze_time('2014-01-01T00:00:00'): CacheService.set_value_for_key('fake_key', 'fake_value', ttl=5) self.assertEquals( CacheService.fetch_value_for_key('fake_key'), 'fake_value', ) with freeze_time('2014-01-01T00:00:06'): self.assertIsNone( CacheService.fetch_value_for_key('fake_key'), )
def _has_seen_hash(self, data_hash): """Gets the value stored at the computed cache key. :param str data_hash: :returns bool: whether or not the hash is in the cache. """ return bool( CacheService.fetch_value_for_key(self._get_cache_key(data_hash)))
def _has_seen_hash(self, data_hash): """Gets the value stored at the computed cache key. :param str data_hash: :returns bool: whether or not the hash is in the cache. """ return bool( CacheService.fetch_value_for_key( self._get_cache_key(data_hash) ) )
def test_get_empty(self): """Test that None is returned if a key hasn't been saved.""" self.assertIsNone(CacheService.fetch_value_for_key('fake_key'))