Skip to content

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

License

Notifications You must be signed in to change notification settings

whosonfirst/go-reader-cachereader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages