Browse files

Custom cache store support

- Allow user to configure own cache engine, (e.g djangos cache)
  • Loading branch information...
1 parent e1ec51c commit d6f9e856ec33b6208aae4a95b220a0556ffa7b19 @robinedwards robinedwards committed Jul 24, 2012
Showing with 46 additions and 1 deletion.
  1. +4 −0 docs/info.rst
  2. +1 −0 neo4jrestclient/options.py
  3. +1 −1 neo4jrestclient/request.py
  4. +40 −0 neo4jrestclient/tests.py
View
4 docs/info.rst
@@ -52,6 +52,10 @@ the same URL will be taken from cache::
neo4jrestclient.options.CACHE = False # Default
+You can also use your own custom cache, (e.g LocMemCache from django)::
+
+ neo4jrestclient.options.CACHE_STORE = LocMemCache()
+
If DEBUG is 'True', 'httplib2' is set to debuglevel = 1::
neo4jrestclient.options.DEBUG = False # Default
View
1 neo4jrestclient/options.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Request
CACHE = False
+CACHE_STORE = '.cache'
DEBUG = False
# Smart errors
SMART_ERRORS = False
View
2 neo4jrestclient/request.py
@@ -16,7 +16,7 @@
else:
httplib2.debuglevel = 0
if options.CACHE:
- http = httplib2.Http(".cache")
+ http = httplib2.Http(options.CACHE_STORE)
else:
http = httplib2.Http()
View
40 neo4jrestclient/tests.py
@@ -1248,6 +1248,46 @@ def test_relationship_pickle(self):
class Neo4jPythonClientTestCase(PickleTestCase):
pass
+
+class FakeCache(object):
+ def __init__(self, called):
+ self.called = called
+
+ def get(self, key):
+ self.called['get'] = True
+ return None
+
+ def set(self, key, value):
+ self.called['set'] = True
+
+ def delete(self, key):
+ pass
+
+
+class XtraCacheTestCase(unittest.TestCase):
+ def setUp(self):
+ self.cache_called = {}
+ options.CACHE = True
+ options.CACHE_STORE = FakeCache(self.cache_called)
+ # reload modules now cache set
+ del sys.modules['neo4jrestclient.request']
+ del sys.modules['neo4jrestclient.client']
+ import client
+ gdb = client.GraphDatabase(NEO4J_URL)
+
+ def test_custom_cache_used(self):
+ self.assertTrue(self.cache_called['get'])
+ self.assertTrue(self.cache_called['set'])
+
+ def tearDown(self):
+ # leave everything as we found it
+ options.CACHE = False
+ options.CACHE_STORE = '.cache'
+ del sys.modules['neo4jrestclient.request']
+ del sys.modules['neo4jrestclient.client']
+ import client
+
+
if __name__ == '__main__':
test_loader = unittest.TestLoader()
suite = test_loader.loadTestsFromTestCase(Neo4jPythonClientTestCase)

0 comments on commit d6f9e85

Please sign in to comment.