Documentation ¶
Overview ¶
Package docstorecache provides an httpclient Cache based on docstore.
Google Cloud Firestore:
const docURL = "firestore://projects/my-project/databases/(default)/documents/httpcache?name_field=Key" coll, err := docstore.OpenCollection(context.Background(), docURL) if err != nil { log.Fatalf("Error opening collection (%s): %v", docURL, err) } defer coll.Close() cache := New(coll) cachingTransport := httpcache.NewTransport(cache) client := cachingTransport.Client() resp, err := client.Get("http://www.google.com/robots.txt") if err != nil { // handle error } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) fmt.Printf("%s", string(body))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DocstoreCache ¶
type DocstoreCache struct {
Collection *docstore.Collection
}
DocstoreCache is an implementation of a Cache that stores responses in a Go Cloud Docstore (Google Cloud Firestore, Amazon DynamoDB, Azure Cosmos DB , etc).
func New ¶
func New(collection *docstore.Collection) *DocstoreCache
New returns a new Cache that uses a docstore collection. When creating the collection you must indicate that "Key" is the primary field (partition key, name, id).
func (*DocstoreCache) Delete ¶
func (c *DocstoreCache) Delete(k string)
Delete attempts to remove an item from docstore.
func (*DocstoreCache) Get ¶
func (c *DocstoreCache) Get(k string) (resp []byte, ok bool)
Get attempts to retrive a cached item from docstore.
func (*DocstoreCache) Set ¶
func (c *DocstoreCache) Set(k string, resp []byte)
Set attempts to save an item in docstore. Errors are silently ignored.
Click to show internal directories.
Click to hide internal directories.