luet/vendor/github.com/rancher-sandbox/gofilecache
Ettore Di Giacinto a6b6909dc4 Update vendor
2021-10-19 21:25:01 +02:00
..
.gitignore Update vendor 2021-10-19 21:25:01 +02:00
cache.go Update vendor 2021-10-19 21:25:01 +02:00
go.mod Update vendor 2021-10-19 21:25:01 +02:00
go.sum Update vendor 2021-10-19 21:25:01 +02:00
gofilecache.go Update vendor 2021-10-19 21:25:01 +02:00
hash.go Update vendor 2021-10-19 21:25:01 +02:00
LICENSE Update vendor 2021-10-19 21:25:01 +02:00
README.md Update vendor 2021-10-19 21:25:01 +02:00

GOFILECACHE

This is a simple filecache derived from golangs buildcache.

How to use

package main

import (
  "crypto/sha512"
  "io/ioutil"
  "os"
  "github.com/rancher-sandbox/gofilecache"
)

func main() {
  // Initialise cache
  cache := gofilecache.InitCache("temp/")
  // pick an example textfile to add to the cache
  testFile := "/usr/lib/os-release"
  file, _ := os.Open(testFile)
  defer file.Close()
  // generate a hash under which the entry can be found in the cache
  // for simplicity we use the filename here
  actionID := sha512.Sum512([]byte("os-release"))

  // store the files contents to the cache
  cache.Put(actionID, file)

  // retrieve the filename from the cache
  fileName, _, _ := cache.GetFile(actionID)

  // get the files contents
  _, _ = ioutil.ReadFile(fileName)
}