Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/vendor/
/vendor/
.idea/
.vs/
.vscode/
38 changes: 38 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,44 @@ func (c *Client) Middleware(next http.Handler) http.Handler {
})
}

// Drop releases the underlying cache for the request's URL.
func (c *Client) Drop(r *http.Request) {
params := r.URL.Query()
key := generateKey(r.URL.String())

if r.Method == http.MethodPost && r.Body != nil {
body, err := io.ReadAll(r.Body)
defer r.Body.Close()
if err != nil {
return
}

reader := io.NopCloser(bytes.NewBuffer(body))
key = generateKeyWithBody(r.URL.String(), body)
r.Body = reader
}

if _, ok := params[c.refreshKey]; ok {
delete(params, c.refreshKey)

r.URL.RawQuery = params.Encode()
key = generateKey(r.URL.String())
}

c.adapter.Release(key)
}

// AddOptions allows the addition or re-application of options after a client has been created.
func (c *Client) AddOptions(opts ...ClientOption) error {
for _, opt := range opts {
if err := opt(c); err != nil {
return err
}
}

return nil
}

func (c *Client) cacheableMethod(method string) bool {
for _, m := range c.methods {
if method == m {
Expand Down