-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcache.go
More file actions
80 lines (61 loc) · 1.9 KB
/
cache.go
File metadata and controls
80 lines (61 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package sawyer
import (
"errors"
"github.com/lostisland/go-sawyer/hypermedia"
"net/http"
)
// A Cacher has the ability to get and set caches for HTTP requests and resource
// relations. See the sawyer/httpcache package.
type Cacher interface {
// Get gets a CachedResponse for the given request.
Get(*http.Request) (CachedResponse, error)
// Set caches the response for the given request.
Set(*http.Request, *Response) error
// Reset removes the cached response and body, but leaves the cached relations.
Reset(*http.Request) error
// Clear removes all cached information for the request.
Clear(*http.Request) error
// UpdateCache updates the cache for the given request with the expiration from
// the response.
UpdateCache(*http.Request, *http.Response) error
// SetRels caches the given relations for the request.
SetRels(*http.Request, hypermedia.Relations) error
// Rels gets the cached relations for the given request.
Rels(*http.Request) (hypermedia.Relations, bool)
}
// CachedResponse is an interface for the httpcache CachedResponseDecoder.
type CachedResponse interface {
Decode(*Request) *Response
SetupRequest(*http.Request)
IsFresh() bool
IsExpired() bool
}
type noOpCache struct{}
func (c *noOpCache) Get(req *http.Request) (CachedResponse, error) {
return nil, noOpError
}
func (c *noOpCache) Set(req *http.Request, res *Response) error {
return nil
}
func (c *noOpCache) UpdateCache(req *http.Request, res *http.Response) error {
return nil
}
func (c *noOpCache) Reset(req *http.Request) error {
return nil
}
func (c *noOpCache) Clear(req *http.Request) error {
return nil
}
func (c *noOpCache) SetRels(req *http.Request, rels hypermedia.Relations) error {
return nil
}
func (c *noOpCache) Rels(req *http.Request) (hypermedia.Relations, bool) {
return nil, false
}
var (
noOpError = errors.New("No Response")
noOpCacher Cacher
)
func init() {
noOpCacher = &noOpCache{}
}