Last active
August 29, 2015 14:17
-
-
Save djherbis/be170c3f3a5e489ce216 to your computer and use it in GitHub Desktop.
FsCache Example.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"io" | |
"log" | |
"net/http" | |
"github.com/djherbis/fscache" | |
) | |
// This will only get called on a cache-miss | |
func Handler(w http.Response, r *http.Request) { | |
io.Copy(w, expensiveProcessReader(r.URL.String())) | |
} | |
func main(){ | |
// Create a new cache directory, expire items after 6 hours of inactivity | |
c, err := fscache.New("./cache", 0700, 6*time.Hour) | |
if err != nil { | |
log.Fatal(err.Error()) | |
} | |
// That's it? Yep. | |
http.LisenAndServe(":8080", fscache.Handler(c, http.HandlerFunc(Handler))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment