From 13758581e7c8a5cbfcedb1b8c0eb4089a058ff80 Mon Sep 17 00:00:00 2001 From: Jonathan Leech-Pepin Date: Tue, 18 Nov 2014 14:28:15 -0500 Subject: Provide cache invalidation (sx-cache--invalidate): Invalidate provided cache. Allows for invalidating variables associated with cache using `makunbound`. Cache can be reinitialized using arg `init-method`. (sx-cache-invalidate-all): Invalidate all caches then call `sx-initialize` to reinitialize. Arg `save-auth` prevents access_token from being lost. --- sx-cache.el | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'sx-cache.el') diff --git a/sx-cache.el b/sx-cache.el index e3b356b..45b379c 100644 --- a/sx-cache.el +++ b/sx-cache.el @@ -67,6 +67,32 @@ DATA will be written as returned by `prin1'." (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 set 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 (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 -- cgit v1.2.3 From b06364055527d93fcea18376befe060c28f97317 Mon Sep 17 00:00:00 2001 From: Jonathan Leech-Pepin Date: Tue, 18 Nov 2014 14:40:15 -0500 Subject: Fix docstring. --- sx-cache.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'sx-cache.el') diff --git a/sx-cache.el b/sx-cache.el index 45b379c..1e64f4f 100644 --- a/sx-cache.el +++ b/sx-cache.el @@ -70,8 +70,7 @@ DATA will be written as returned by `prin1'." (defun sx-cache--invalidate (cache &optional vars init-method) "Set cache CACHE to nil. -VARS is a list of variables to set to unbind to ensure cache is -cleared. +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) -- cgit v1.2.3 From 7e3685bf944378c49738de2ee2c685af785806b6 Mon Sep 17 00:00:00 2001 From: Jonathan Leech-Pepin Date: Tue, 18 Nov 2014 14:52:38 -0500 Subject: Use `cl-remove-if` rather than `remove-if` --- sx-cache.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sx-cache.el') diff --git a/sx-cache.el b/sx-cache.el index 1e64f4f..a564a53 100644 --- a/sx-cache.el +++ b/sx-cache.el @@ -86,7 +86,7 @@ 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 (remove-if (lambda (x) + (setq caches (cl-remove-if (lambda (x) (string= x "auth.el")) caches))) (lwarn 'stack-mode :debug "Invalidating: %S" caches) (mapc #'sx-cache--invalidate caches) -- cgit v1.2.3