Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag and function name based lookup "tables" #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions redis_cache/redis_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,42 @@ def wrapper(*args, **kwargs):
)
else:
self.redis_client.set(fn_hash, ret, **options)

# Add the hash to the fn_name and tags lookup tables
self.redis_client.sadd(fn_name, fn_hash)

if 'tags' in options:
tags = options.get('tags')
for tag in tags:
self.redis_client.sadd(tag, fn_hash)

else:
# Cache hit
return cache_request
return ret
return wrapper
return cache_inside

def get_tag_cache(tag):
return self.redis_client.smembers(tag)

def reset_tag_cache(tag):
caches = self.redis_client.smembers(tag)
self.redis_client.delete(caches)
self.redis_client.delete(tag)

def get_function_cache(fn_name):
self.get_tag_cache(fn_name)

def reset_function_cache(fn_name):
self.reset_tag_cache(fn_name)

def get_function_instance_cache():
raise NotImplemented()

def reset_function_instance_cache():
raise NotImplemented()

def _get_signature(*args, **kwargs):
"""
Gets the signature of the decorated method
Expand Down
22 changes: 22 additions & 0 deletions tests/test_redis_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,25 @@ def test_function(a):
mock_client.get.assert_called_once_with(expected_hash)
self.assertEqual(mock_client.set.call_count, 0)
self.assertEqual(function_response, test_param)

@patch('redis_cache.redis_cache.RedisClient')
def test_cache_get_tag_cache(self, mock_client_object):
pass

@patch('redis_cache.redis_cache.RedisClient')
def test_cache_reset_tag_cache(self, mock_client_object):
pass

@patch('redis_cache.redis_cache.RedisClient')
def test_cache_get_function_cache(self, mock_client_object):
pass

@patch('redis_cache.redis_cache.RedisClient')
def test_cache_reset_function_cache(self, mock_client_object):
pass

def test_get_function_instance_cache(self, mock_client_object):
raise NotImplemented()

def test_reset_function_instance_cache(self, mock_client_object):
raise NotImplemented()