Adding to utils make-weak-hash-table for use in caches.
[clsql.git] / sql / utils.lisp
index 60fedc3f971d4a8fd6b9b2d39471dfcb5350064d..6e4230d84d94486d8448cc9c84f9c89839bd47e4 100644 (file)
@@ -405,3 +405,22 @@ removed. keys are searched with #'MEMBER"
           unless (member k keys-to-remove)
             collect k and collect v
           while rest)))
+
+(defmacro make-weak-hash-table (&rest args)
+  "Creates a weak hash table for use in a cache."
+  `(progn
+
+    ;;NB: These are generally used for caches that may not have an alternate
+    ;;clearing mechanism. If you are on an implementation that doesn't support
+    ;;weak hash tables then you're memory may accumulate.
+
+    #-(or sbcl allegro clisp lispworks)
+    (warn "UNSAFE! use of weak hash on implementation without support. (see clsql/sql/utils.lisp to add)")
+
+    (make-hash-table
+      #+allegro   :values    #+allegro :weak
+      #+clisp     :weak      #+clisp :value
+      #+lispworks :weak-kind #+lispworks :value
+      #+sbcl :weakness #+sbcl :value
+      ,@args)
+    ))