https://github.com/whosonfirst/go-reader-cachereader
Go package implementing the whosonfirst/go-reader interface for use with a caching layer.
https://github.com/whosonfirst/go-reader-cachereader
golang whosonfirst whosonfirst-reader
Last synced: 3 months ago
JSON representation
Go package implementing the whosonfirst/go-reader interface for use with a caching layer.
- Host: GitHub
- URL: https://github.com/whosonfirst/go-reader-cachereader
- Owner: whosonfirst
- License: bsd-3-clause
- Created: 2020-01-07T17:36:37.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-05-12T23:21:27.000Z (about 1 year ago)
- Last Synced: 2025-01-17T20:16:22.622Z (4 months ago)
- Topics: golang, whosonfirst, whosonfirst-reader
- Language: Go
- Homepage:
- Size: 282 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-reader-cachereader
Go package implementing the `whosonfirst/go-reader` interface for use with a caching layer.
## Documentation
[](https://pkg.go.dev/github.com/whosonfirst/go-reader-cachereader)
## Example
```
package mainimport (
"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
* https://github.com/whosonfirst/go-reader
* https://github.com/whosonfirst/go-cache