Categorygithub.com/geekypanda/httpcache
modulepackage
0.0.1
Repository: https://github.com/geekypanda/httpcache.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# Functions

Cache accepts two parameters first is the http.Handler which you want to cache its result the second is, optional, the cache Entry's expiration duration if the expiration <=2 seconds then expiration is taken by the "cache-control's maxage" header returns an http.Handler, which you can use as your default router or per-route handler All type of responses are cached, templates, json, text, anything.
Clear removes all entries from the default cache.
Invalidate accepts a *http.Request which is used to find the cache key and removes any releated Entry from the cache.
NewMemoryStore returns a new memory store for the cache , note that httpcache package provides one global default cache service which provides these functions: `httpcache.Cache`, `httpcache.Invalidate` and `httpcache.Start` If you use only one global cache for all of your routes use the `httpcache.New` instead.
NewService returns a new cache Service with the given store.
NewServiceFasthttp returns a new cache Service with the given store.
Request , or remote cache client whatever you like, it's the client-side function of the ServeHTTP sends a request to the server-side remote cache Service and sends the cached response to the frontend client it is used only when you achieved something like horizontal scaling (separate machines) look ServeHTTP for more if cache din't find then it sends a POST request and save the bodyHandler's body to the remote cache.
RequestFasthttp , it's the client-side function, sends a request to the server-side remote cache Service and parses the cached response it is used only when you achieved something like horizontal scaling (separate machines) and you have an already running remote cache Service or ServiceFasthttp look ServeHTTP for more if cache din't find then it sends a POST request and save the bodyHandler's body to the remote cache.
ServeHTTP serves the cache Service to the outside world, it is used only when you want to achieve something like horizontal scaling (separate machines) it parses the request and tries to return the response with the cached body of the requested cache key server-side function.

# Variables

Client is used inside the global Request function this client is an exported to give you a freedom of change its Transport, Timeout and so on(in case of ssl).
ClientFasthttp is used inside the global RequestFasthttp function this client is an exported variable because the maybe the remote cache service is running behind ssl, in that case you are able to set a Transport inside it.
Default is default package-level instance of the net/http cache service with a memory store USAGE: http.ListenAndServe("mydomain.com",httpcache.Cache(myRouter, 20* time.Second)) or for individual handlers: httpcache.Cache(myHandler, 20* time.Secnd) .
Fasthttp is the package-level instance of valyala/fasthttp cache service with a memory store has the same functions as httpcache and httpcache.NewService(), which is the net/http cache USAGE: fasthttp.ListenAndServe("mydomain.com",httpcache.Fasthttp.Cache(myRouter, 20* time.Second)) or for individual handlers: httpcache.Fasthttp.Cache(myRequestHandler, 20* time.Secnd) .
GC checks for expired cache entries and deletes them every tick of this time set it to <=2*time.Second to disable GC for all default cache services' memory stores.

# Structs

Entry
No description provided by the author
Service contains the cache and performs actions to save cache and serve cached content.
ServiceFasthttp contains the cache and performs actions to save cache and serve cached content.

# Interfaces

No description provided by the author