@@ -16,7 +16,6 @@ import (
1616 "net/http"
1717 "net/http/httputil"
1818 "strings"
19- "sync"
2019 "time"
2120)
2221
@@ -78,46 +77,6 @@ func (t *Transport) cachedResponse(req *http.Request) (resp *http.Response, err
7877 return http .ReadResponse (bufio .NewReader (b ), req )
7978}
8079
81- // memoryCache is an implemtation of Cache that stores responses in an in-memory map.
82- type memoryCache struct {
83- mu sync.RWMutex
84- items map [string ][]byte
85- }
86-
87- func (c * memoryCache ) Size () int {
88- c .mu .RLock ()
89- defer c .mu .RUnlock ()
90- return len (c .items )
91- }
92-
93- // Get returns the []byte representation of the response and true if present, false if not
94- func (c * memoryCache ) Get (key string ) (resp []byte , ok bool ) {
95- c .mu .RLock ()
96- resp , ok = c .items [key ]
97- c .mu .RUnlock ()
98- return resp , ok
99- }
100-
101- // Set saves response resp to the cache with key
102- func (c * memoryCache ) Set (key string , resp []byte ) {
103- c .mu .Lock ()
104- c .items [key ] = resp
105- c .mu .Unlock ()
106- }
107-
108- // Delete removes key from the cache
109- func (c * memoryCache ) Delete (key string ) {
110- c .mu .Lock ()
111- delete (c .items , key )
112- c .mu .Unlock ()
113- }
114-
115- // newMemoryCache returns a new Cache that will store items in an in-memory map
116- func newMemoryCache () * memoryCache {
117- c := & memoryCache {items : map [string ][]byte {}}
118- return c
119- }
120-
12180// Transport is an implementation of http.RoundTripper that will return values from a cache
12281// where possible (avoiding a network request) and will additionally add validators (etag/if-modified-since)
12382// to repeated requests allowing servers to return 304 / Not Modified
@@ -617,10 +576,3 @@ func (r *cachingReadCloser) Read(p []byte) (n int, err error) {
617576func (r * cachingReadCloser ) Close () error {
618577 return r .R .Close ()
619578}
620-
621- // newMemoryCacheTransport returns a new Transport using the in-memory cache implementation
622- func newMemoryCacheTransport () * Transport {
623- c := newMemoryCache ()
624- t := & Transport {Cache : c }
625- return t
626- }
0 commit comments