emacs-gitlab icon indicating copy to clipboard operation
emacs-gitlab copied to clipboard

Caching ?

Open vindarel opened this issue 8 years ago • 1 comments

Hi,

Do you plan to do some caching of the api results, and if so how would you implement it ?

vindarel avatar Jan 20 '17 01:01 vindarel

very first iteration, using pcache: https://github.com/sigma/pcache (p for persistent)

(defvar gitlab-cache-expiry 3600 "Time expiry of cache, in seconds. Bypass it with an optional argument (C-u).") ;; bypass to do

(defun gitlab--perform-get-request (uri params)
  "Doc string URI PARAMS. Cache requests."
  (let* ((repo-name (concat "gitlab/" uri))  ;; so we can find our repositories easily
         (repo (pcache-repository repo-name))
         (data (pcache-get repo 'response)))
    (if data
        (pcache-get repo 'response)

      (let* ((response (request (gitlab--get-rest-uri uri)
                                :type "GET"
                                :headers (gitlab--get-headers)
                                :sync t
                                :params params
                                ;;:data params
                                :parser 'json-read)))
        (pcache-put repo 'response response gitlab-cache-expiry)
        response))))

it basically stores the request response into a cache object for a given number of seconds.

Not satisfactory yet 'cause

  • there should be a way to bypass the cache (optional argument)
  • we must cache not just the call to a given url but also take into account the parameters.

pcache doesn't have a list of created caches (apparently), and we may need one.

vindarel avatar May 17 '17 22:05 vindarel