luet/vendor/github.com/rancher-sandbox/gofilecache
Ettore Di Giacinto 5ee1ff6d5a
⬆️ Bump to go 1.19 as requirement for building (#319)
* ⬆️ Bump to go 1.19 as requirement for building

Signed-off-by: mudler <mudler@c3os.io>

* ⬆️ Update vendor

* 🤖 Use go 1.19 in CI

* 🤖 Do not pull cover from makefile

Signed-off-by: mudler <mudler@c3os.io>

* 🤖 Fix permission issues

Signed-off-by: mudler <mudler@c3os.io>

* 🤖 Adapt test to getcap output changes

Signed-off-by: mudler <mudler@c3os.io>

---------

Signed-off-by: mudler <mudler@c3os.io>
2023-02-02 11:59:57 +01:00
..
.gitignore Update vendor 2021-10-19 21:25:01 +02:00
cache.go 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)
}