Skip to content

Commit

Permalink
Add experimental cache-count-queries resource feature
Browse files Browse the repository at this point in the history
The cache-count-queries resource feature allows caching of model
properties on a per-resource basis.  This means that you can set some
resources not to have their model properties cached, whilst others
would have such a cache.

Use :features '(cache-count-queries) in the define-resource.

This feature is EXPERIMENTAL.  We intend to merge this feature with
other features and/or to merge it over time.
  • Loading branch information
madnificent committed Dec 2, 2018
1 parent e44af1c commit 467bbcf
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion framework/response-generation.lisp
Expand Up @@ -6,6 +6,12 @@
(parse-integer entity :junk-allowed t)
(error () nil)))

(defun cache-count-queries-p (resource)
"Returns a truethy value iff the count queries should be cached for
resource."
(or *cache-count-queries-p*
(find 'cache-count-queries (features resource))))

(defun count-matches (identifier-variable query-body resource link-spec)
"Returns the amount of matches for a particular response."
(flet ((sparql-count ()
Expand All @@ -14,7 +20,7 @@
identifier-variable)
query-body))
"count" "value"))))
(if *cache-count-queries-p*
(if (cache-count-queries-p resource)
(or (count-cache resource link-spec)
(setf (count-cache resource link-spec) (sparql-count)))
(sparql-count))))
Expand Down

0 comments on commit 467bbcf

Please sign in to comment.