aboutsummaryrefslogtreecommitdiff
path: root/sx-cache.el
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2014-11-18 23:49:07 -0500
committerSean Allred <code@seanallred.com>2014-11-19 00:00:42 -0500
commit0dd95e3a3d4ee52f52a585388c3ba65e045c305b (patch)
treef8c4497519cf6f741ea7ec379c537f4b71a4de88 /sx-cache.el
parent20dd7254da8e95bd01ce57f806733dee20005039 (diff)
parent681319aeb250a83d982d1e3e02264a7af0ae4120 (diff)
Merge branch 'master' into documentation
Conflicts: sx-method.el sx-question-list.el sx-question-mode.el sx-question.el sx-request.el sx.el
Diffstat (limited to 'sx-cache.el')
-rw-r--r--sx-cache.el25
1 files changed, 25 insertions, 0 deletions
diff --git a/sx-cache.el b/sx-cache.el
index 80b6ced..63025ea 100644
--- a/sx-cache.el
+++ b/sx-cache.el
@@ -72,6 +72,31 @@ CACHE is resolved to a file name by `sx-cache-get-file-name'."
(sx-cache-get-file-name cache))
data)
+(defun sx-cache--invalidate (cache &optional vars init-method)
+ "Set cache CACHE to nil.
+
+VARS is a list of variables to unbind to ensure cache is cleared.
+If INIT-METHOD is defined, call it after all invalidation to
+re-initialize the cache."
+ (sx-cache-set cache nil)
+ (mapc #'makunbound vars)
+ (funcall init-method))
+
+(defun sx-cache-invalidate-all (&optional save-auth)
+ "Invalidate all caches using `sx-cache--invalidate'.
+
+Afterwards reinitialize caches using `sx-initialize'.
+
+If SAVE-AUTH is non-nil, do not clear AUTH cache."
+ (let ((caches (let ((default-directory sx-cache-directory))
+ (file-expand-wildcards "*.el"))))
+ (when save-auth
+ (setq caches (cl-remove-if (lambda (x)
+ (string= x "auth.el")) caches)))
+ (lwarn 'stack-mode :debug "Invalidating: %S" caches)
+ (mapc #'sx-cache--invalidate caches)
+ (sx-initialize 'force)))
+
(provide 'sx-cache)
;;; sx-cache.el ends here