1
0
Fork 0
gobelt/filecache
Gregory Eremin 993153693a Move readme parts to their corresponding packages 2018-07-03 20:33:55 +02:00
..
README.md Move readme parts to their corresponding packages 2018-07-03 20:33:55 +02:00
filecache.go Stuff 2018-06-24 16:36:44 +02:00
filecache_test.go Stuff 2018-06-24 16:36:44 +02:00

README.md

File cache

Package file_cache implements a helper function that would cache results of an expensive operation to a file. It would use file contents when the file exist and won't call the function again unless the file is deleted.

import "github.com/localhots/gobelt/filecache"
ctx := context.Background()
var items []Item
filecache.Load(&items, "tmp/cache/items.json", func() {  
    err := conn.Query(ctx, "SELECT * FROM items").Load(&items).Error()
    if err != nil {
        log.Fatalf("Failed to load items: %v", err)
    }
})