 ;;;###autoload
 (defun doom-store-clear (&optional location)
   "Clear the store at LOCATION (defaults to `doom-store-location')."
+  (cl-check-type location (or null string))
   (let* ((location (or location doom-store-location))
          (path (expand-file-name location doom-store-dir)))
     (remhash location doom--store-table)

`doom-store-dir'). One file may contain multiple cache entries.")

(defvar doom--store-table (make-hash-table :test 'equal))
(defvar doom--inhibit-flush nil)

(defun doom-save-persistent-store-h ()
  "Hook to run when an Emacs session is killed. Saves all persisted variables
listed in `doom-store-persist-alist' to files."
  (let (locations)
    (let ((doom--inhibit-flush t))
      (dolist (alist (butlast doom-store-persist-alist 1))
        (cl-loop with location = (car alist)
                 for var in (cdr alist)
                 do (doom-store-put var (symbol-value var) nil location)
                 and do (cl-pushnew location locations))))
    (mapc #'doom--store-flush locations)))
(add-hook 'kill-emacs-hook #'doom-save-persistent-store-h)


          (puthash location (make-hash-table :test 'equal)
                   doom--store-table)))))

(defun doom--store-expired-p (key data)
  (let ((ttl (car data)))
    (cond ((functionp ttl)
           (not (funcall ttl key data)))
          ((integerp ttl)
           (time-less-p ttl (current-time))))))

(defun doom--store-flush (location)
  "Write `doom--store-table' to `doom-store-dir'."
  (let ((file-name-handler-alist nil)
        (coding-system-for-write 'binary)
        (write-region-annotate-functions nil)
        (write-region-post-annotation-function nil)
        (data (doom--store-init location)))
    (make-directory doom-store-dir 'parents)
    (with-temp-file (expand-file-name location doom-store-dir)
      (prin1 data (current-buffer)))
    data))


;;;###autoload
(defun doom-store-get (key &optional location default-value noflush)
  "Retrieve KEY from LOCATION (defaults to `doom-store-location').
If it doesn't exist or has expired, DEFAULT_VALUE is returned."
  (let ((location (or location doom-store-location))
        (data (gethash key (doom--store-init location) default-value)))
    (if (not (doom--store-expired-p key data))
        (cdr data)
      (doom-store-rem key location noflush)
      default-value)))

;;;###autoload
(defun doom-store-put (key value &optional ttl location noflush)
  "Set KEY to VALUE in the store at LOCATION.
KEY can be any lisp object that is comparable with `equal'. TTL is the duration
(in seconds) after which this cache entry expires; if nil, no cache expiration.
LOCATION is the super-key to store this cache item under. It defaults to
`doom-store-location'."
  (cl-check-type ttl (or null integer function))
  (let ((location (or location doom-store-location)))
    (puthash key (cons (if (integerp ttl)
                           (time-add (current-time) ttl)
                         ttl)
                       value)
             (doom--store-init location))
    (unless noflush
      (doom--store-flush location))))

;;;###autoload
(defun doom-store-rem (key &optional location noflush)
  "Clear a cache LOCATION (defaults to `doom-store-location')."
  (let ((location (or location doom-store-location)))
    (remhash key (doom--store-init location))
    (unless noflush
      (doom--store-flush location))))

;;;###autoload
(defun doom-store-member-p (key &optional location)
