Categorygithub.com/whosonfirst/go-reader-cachereader

# Packages

No description provided by the author

# 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"
	"io/ioutil"
	"log"

	_ "github.com/whosonfirst/go-reader-cachereader/v2"
	
	"github.com/whosonfirst/go-reader/v2"
)

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