Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( // DefaultMaxAge is default max-age value DefaultMaxAge = 30 * time.Second // HeaderCacheControl as in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control HeaderCacheControl = "Cache-Control" // HeaderExpires as in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expires HeaderExpires = "Expires" // HeaderLastModified as in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified HeaderLastModified = "Last-Modified" // HeaderIfModifiedSince as in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since HeaderIfModifiedSince = "If-Modified-Since" )
Variables ¶
View Source
var ( // ErrNotModified happen when conditional request apply ErrNotModified = errors.New("Cache: not modified") )
Functions ¶
func NotModifiedError ¶
NotModifiedError return true if error is not modified error
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache data
Example ¶
var ( data string server *miniredis.Miniredis err error ) // run redis server if server, err = miniredis.Run(); err != nil { log.Fatal(err.Error()) } defer server.Close() // create redis client client := redis.NewClient(&redis.Options{Addr: server.Addr()}) // define key and refresh function for your cache cache := cachekit.New("some-key", func() (interface{}, error) { return "fresh-data", nil }) // execute cache to get the data if err = cache.Execute(client, &data, pragmaWithCacheControl("")); err != nil { log.Fatal(err.Error()) } fmt.Println(data)
Output: fresh-data
type Pragma ¶
type Pragma struct {
// contains filtered or unexported fields
}
Pragma handle pragmatic information/directives for caching
func CreatePragma ¶
CreatePragma to create new instance of CacheControl from request
func (*Pragma) IfModifiedSince ¶
IfModifiedSince return if-modified-since value
func (*Pragma) ResponseHeaders ¶
ResponseHeaders return map that contain response header
func (*Pragma) SetExpiresByTTL ¶
SetExpiresByTTL to set expires to current time to TTL
func (*Pragma) SetLastModified ¶
SetLastModified to set last-modified
Click to show internal directories.
Click to hide internal directories.