diff options
author | Jonathan Leech-Pepin <jonathan.leechpepin@gmail.com> | 2014-11-17 09:08:36 -0500 |
---|---|---|
committer | Jonathan Leech-Pepin <jonathan.leechpepin@gmail.com> | 2014-11-17 09:08:36 -0500 |
commit | 5ef7b4683cc8feceee0b8862df987a0bdde7a0f1 (patch) | |
tree | 328265178cadccaa79a900eccc34481ed96f7156 /sx-cache.el | |
parent | a3d1ea047d0f4a5d4c4900b95de66955e65aa3d5 (diff) | |
parent | abb70f545aa7594a7c37e8335614c23a692b8a03 (diff) |
Merge branch 'master' into sx-request-make-update
Diffstat (limited to 'sx-cache.el')
-rw-r--r-- | sx-cache.el | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/sx-cache.el b/sx-cache.el index 098c292..e3b356b 100644 --- a/sx-cache.el +++ b/sx-cache.el @@ -38,18 +38,21 @@ (concat (symbol-name filename) ".el") sx-cache-directory)) -(defun sx-cache-get (cache) +(defun sx-cache-get (cache &optional form) "Return the data within CACHE. +If CACHE does not exist, evaluate FORM and set it to its return. + As with `sx-cache-set', CACHE is a file name within the context of `sx-cache-directory'." (unless (file-exists-p sx-cache-directory) (mkdir sx-cache-directory)) (let ((file (sx-cache-get-file-name cache))) - (when (file-exists-p file) - (with-temp-buffer - (insert-file-contents (sx-cache-get-file-name cache)) - (read (buffer-string)))))) + (if (file-exists-p file) + (with-temp-buffer + (insert-file-contents (sx-cache-get-file-name cache)) + (read (buffer-string))) + (sx-cache-set cache (eval form))))) (defun sx-cache-set (cache data) "Set the content of CACHE to DATA. |