aboutsummaryrefslogtreecommitdiff
path: root/stack-core.el
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2014-11-02 13:11:15 -0500
committerSean Allred <code@seanallred.com>2014-11-02 13:11:15 -0500
commitf349fe5d764730a0a339045a59a46d53b9a33100 (patch)
tree37259374736486ce6398680522f3577b659b9c17 /stack-core.el
parent73a1b008211cc2ca548c30ff99b2950c99e53325 (diff)
Implement and use `stack-cache-get' and `-set'
Diffstat (limited to 'stack-core.el')
-rw-r--r--stack-core.el30
1 files changed, 23 insertions, 7 deletions
diff --git a/stack-core.el b/stack-core.el
index f9b9669..c2aff15 100644
--- a/stack-core.el
+++ b/stack-core.el
@@ -249,13 +249,29 @@ entire response as a complex alist."
"Expands FILENAME in the context of `stack-cache-directory'."
(expand-file-name filename stack-cache-directory))
-(defun stack-cache-get-file (filename)
- "Return a buffer for FILENAME from `stack-cache-directory'."
- (let ((find-file-hook nil)
- (file (stack-cache-get-file-name filename)))
- (unless (file-exists-p stack-cache-directory)
- (mkdir stack-cache-directory))
- (find-file-noselect file)))
+(defun stack-cache-get (cache)
+ "Return the data within CACHE.
+
+As with `stack-cache-set', CACHE is a file name within the
+context of `stack-cache-directory'."
+ (unless (file-exists-p stack-cache-directory)
+ (mkdir stack-cache-directory))
+ (let ((file (stack-cache-get-file-name cache)))
+ (when (file-exists-p file)
+ (with-temp-buffer
+ (insert-file-contents (stack-cache-get-file-name cache))
+ (read (buffer-string))))))
+
+(defun stack-cache-set (cache data)
+ "Set the content of CACHE to DATA.
+
+As with `stack-cache-get', CACHE is a file name within the
+context of `stack-cache-directory'."
+ (unless (file-exists-p stack-cache-directory)
+ (mkdir stack-cache-directory))
+ (write-region (prin1-to-string data) nil
+ (stack-cache-get-file-name cache))
+ data)
(provide 'stack-core)
;;; stack-core.el ends here