Commits

John Chandler committed 7be8594

Added tests and code for unloading proxy cache entries

Comments (0)

Files changed (2)

django_fluidproxy.py

 
 import hashlib
 
-from fom.session import Fluid
+from django.core.cache import cache
+from fom.session       import Fluid
 
-from django.core.cache import cache
 
+def generate_cache_key( path ):
+    """ Returns a key suitable for calls to cache """
+    h = hashlib.sha1()
+    h.update( path )
+    
+    return "fluidproxy:%s" % h.hexdigest()
+    
 
 class FluidAPIProxy( object ):
     """ A FluidDB API proxy class for use with Django.
         """ Preload proxy cache
             path  = FluidDB path e.g. /path/to/tag
             value = value of path
+        """        
+        cache.set( generate_cache_key(path), value )
+
+    def unload( self, path ):
+        """ Unload proxy cache
+            path = FluidDB path e.g. /path/to/tag
         """
-        h = hashlib.sha1()
-        h.update( path )
-        key = "fluidproxy:%s" % h.hexdigest()
-        
-        cache.set( key, value )
+        cache.delete( generate_cache_key(path) )
     
         self.proxy.preload( "/metaljoe/test/foo", value=value )
 
         self.assertEqual( cache.get(key), value )
+
+    def test_unload_path( self ):
+        """ Tests unloading cache for a simple path """
+        key   = "fluidproxy:a16b1ac35cb8cf6d6e2939d12fe68cee5860d9bc"
+        value = 1234
+
+        cache.set( key, value )
+        self.proxy.unload( "/metaljoe/test/foo" )
+
+        self.assertEqual( cache.get(key), None )
         
 
 if __name__ == "__main__":
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.