diff options
author | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-11-15 02:39:21 +0000 |
---|---|---|
committer | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-11-15 02:39:21 +0000 |
commit | 08c305f573dda0512e3acb1b6c6c78f390a5921d (patch) | |
tree | 995a64999fa5f2dd29042cbb98c02ec51ed0025a /sx-cache.el | |
parent | 884363ac75fe0c5f8e082c31cfeb8632ad85f19e (diff) | |
parent | 7881572c09281785c1d0303d13305b583b3803cd (diff) |
Merge remote-tracking branch 'remotes/origin/network-list' into real-scores
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. |