Categorygithub.com/whosonfirst/go-reader-cachereader
modulepackage
1.1.1
Repository: https://github.com/whosonfirst/go-reader-cachereader.git
Documentation: pkg.go.dev

# README

go-reader-cachereader

Go package implementing the whosonfirst/go-reader interface for use with a caching layer.

Documentation

Go Reference

Example

package main

import (
	"context"
	"fmt"
	"github.com/whosonfirst/go-reader"
	"github.com/whosonfirst/go-reader-cachereader"	
	"io/ioutil"
	"log"
)

func main(){

	ctx := context.Background()

	reader_uri := "fs:///usr/local/data"
	cache_uri := "gocache://"

	cr_uri := fmt.Sprintf("cachereader://?reader=%s&cache=%s", reader_uri, cache_uri)
	
	r, _ := reader.NewReader(ctx, cr_uri)

	path := "101736545.geojson"
	
	for i := 0; i < 3; i++ {

		fh, _ := r.Read(ctx, path)
		defer fh.Close()

		io.Copy(ioutil.Discard, fh)

		status, _ := cachereader.GetLastRead(r, path)

		switch i {
		case 0:
			if status != cachereader.CacheMiss {
				log.Printf("Expected cache miss on first read of %s", path)
			}
		default:
			if status != cachereader.CacheHit {
				log.Printf("Expected cache hit after first read of %s", path)
			}
		}
	}
}

Error handling omitted for the sake of brevity.

See also

# Functions

GetLastRead returns the `CacheStatus` value for the last event using 'cr' to read 'path'.
NewCacheReader will return a new `CacheReader` instance configured by 'uri' which is expected to take the form of: cachereader://?reader={READER_URI}&cache={CACHE_URI} Where {READER_URI} is expected to be a valid `whosonfirst/go-reader.Reader` URI and {CACHE_URI} is expected to be a valid `whosonfirst/go-cache.Cache` URI.
NewCacheReader will return a new `CacheReader` instance configured by 'opts'.

# Constants

CacheHit signals that the last read event was a cache HIT.
CacheHit signals that the last read event was a cache MISS.
CacheNotFound signals that there are no recorded events for a cache lookup.

# Structs

type CacheReader implements the `whosonfirst/go-reader` interface for use with a caching layer for reading documents.
type CacheReaderOptions is a struct for use with the `NewCacheReaderWithOptions` method.

# Type aliases

type CacheStatus is a constant indicating the cache status for a read action.