fscache

Streaming File Cache for #golang

  • 所有者: djherbis/fscache
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

fscache

GoDoc
Release
Software License
Build Status
Coverage Status
Go Report Card

Usage

Streaming File Cache for #golang

fscache allows multiple readers to read from a cache while its being written to. blog post

Using the Cache directly:

package main

import (
	"io"
	"log"
	"os"
	"time"

	"gopkg.in/djherbis/fscache.v0"
)

func main() {

	// create the cache, keys expire after 1 hour.
	c, err := fscache.New("./cache", 0755, time.Hour)
	if err != nil {
		log.Fatal(err.Error())
	}
	
	// wipe the cache when done
	defer c.Clean()

	// Get() and it's streams can be called concurrently but just for example:
	for i := 0; i < 3; i++ {
		r, w, err := c.Get("stream")
		if err != nil {
			log.Fatal(err.Error())
		}

		if w != nil { // a new stream, write to it.
			go func(){
				w.Write([]byte("hello world\n"))
				w.Close()
			}()
		}

		// the stream has started, read from it
		io.Copy(os.Stdout, r)
		r.Close()
	}
}

A Caching Middle-ware:

package main

import(
	"net/http"
	"time"

	"gopkg.in/djherbis/fscache.v0"
)

func main(){
	c, err := fscache.New("./cache", 0700, 0)
	if err != nil {
		log.Fatal(err.Error())
	}

	handler := func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "%v: %s", time.Now(), "hello world")
	}

	http.ListenAndServe(":8080", fscache.Handler(c, http.HandlerFunc(handler)))
}

Installation

go get gopkg.in/djherbis/fscache.v0

主要指標

概覽
名稱與所有者djherbis/fscache
主編程語言Go
編程語言Go (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2015-03-26 02:40:41
推送於2023-11-30 15:41:08
最后一次提交2023-11-27 16:51:53
發布數9
最新版本名稱v0.11 (發布於 )
第一版名稱v0.7.0 (發布於 )
用户参与
星數128
關注者數11
派生數34
提交數162
已啟用問題?
問題數12
打開的問題數4
拉請求數7
打開的拉請求數1
關閉的拉請求數1
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?