Skip to content
Newer
Older
100644 57 lines (42 sloc) 1.85 KB
b904feb @sigma first shot at caching
sigma authored
1 ;;; gh-cache.el --- caching for gh.el
2
3 ;; Copyright (C) 2011 Yann Hodique
4
5 ;; Author: Yann Hodique <yann.hodique@gmail.com>
6 ;; Keywords:
7
8 ;; This file is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
12
13 ;; This file is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
20 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
22
23 ;;; Commentary:
24
25 ;;
26
27 ;;; Code:
28
29 (eval-when-compile
30 (require 'cl))
31
bf60ba8 @sigma fix packaging
sigma authored
32 ;;;###autoload
b904feb @sigma first shot at caching
sigma authored
33 (require 'eieio)
bf60ba8 @sigma fix packaging
sigma authored
34
b904feb @sigma first shot at caching
sigma authored
35 (require 'pcache)
36
37 (defclass gh-cache (pcache-repository)
38 ((entries :initarg :entries :initform (make-hash-table :test 'equal))
bb826f9 @sigma add rare safe verbs
sigma authored
39 (safe-methods :allocation :class :initform ("HEAD" "GET" "OPTIONS" "TRACE"))
b904feb @sigma first shot at caching
sigma authored
40 (invalidation-chain :allocation :class :initform nil)))
41
42 (defmethod pcache-invalidate :after ((cache gh-cache) key)
739e5ab @sigma fix invalidation propagation
sigma authored
43 (let ((resource (car key)))
44 (pcache-map cache #'(lambda (k v)
45 (when (equal (car k) resource)
46 (pcache-invalidate cache k))))
47 (dolist (next (oref cache invalidation-chain))
48 (let ((nextresource
49 (replace-regexp-in-string (car next) (cdr next) resource)))
50 (when (not (equal nextresource resource))
51 (pcache-map cache #'(lambda (k v)
52 (when (equal (car k) nextresource)
53 (pcache-invalidate cache k)))))))))
b904feb @sigma first shot at caching
sigma authored
54
55 (provide 'gh-cache)
56 ;;; gh-cache.el ends here
Something went wrong with that request. Please try again.