(defvar *output-hash*
- #+sbcl
- (make-hash-table :test #'equal :synchronized T :weakness :key-and-value)
- #-sbcl
- (make-hash-table :test #'equal )
- "For caching generated SQL strings.")
+ (make-weak-hash-table :test #'equal)
+ "For caching generated SQL strings, set to NIL to disable."
+ )
(defmethod output-sql :around ((sql t) database)
(if (null *output-hash*)
(defun (setf records-cache-results) (results targets qualifiers database)
(unless (record-caches database)
(setf (record-caches database)
- (make-hash-table :test 'equal
- #+allegro :values #+allegro :weak
- #+clisp :weak #+clisp :value
- #+lispworks :weak-kind #+lispworks :value)))
- (setf (gethash (compute-records-cache-key targets qualifiers)
+ (make-weak-hash-table :test 'equal)))
+ (setf (gethash (compute-records-cache-key (copy-list targets) qualifiers)
(record-caches database)) results)
results)
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)
+ ))