def clear_permission_cache(): """Drop cached permissions for all users.""" if not has_memcache(): return client = get_cache_manager().cache_object.memcache_client # We delete all the cached user permissions as well as # the permissions:list value itself keys_to_delete = list('permissions:list') for user_key in client.get('permissions:list') or set(): keys_to_delete.append(user_key) keys_to_delete.extend(blob_get_chunk_keys(client, user_key)) client.delete_multi(keys_to_delete)
def clear_users_permission_cache(user_ids): """ Drop cached permissions for a list of users. """ if not has_memcache() or not user_ids: return client = get_cache_manager().cache_object.memcache_client keys_to_delete = list() cached_keys_set = client.get('permissions:list') or set() for user_id in user_ids: key = 'permissions:{}'.format(user_id) if key in cached_keys_set: cached_keys_set.remove(key) keys_to_delete.append(key) keys_to_delete.extend(blob_get_chunk_keys(client, key)) client.set('permissions:list', cached_keys_set) client.delete_multi(keys_to_delete)
def test_blob_set(self): """Test blob_set()""" # set cache which will be split to 3 chunks (5+5+1 bytes) memcache.blob_set(self.memcache_client, "a", "01234567890") keys = memcache.blob_get_chunk_keys(self.memcache_client, "a") self.assertEqual(keys, ["a:0", "a:5", "a:10"])