Example #1
0
// CreateCacheAlgol creates the cache algorithm implementation
func (this *CacheBuilderImpl) CreateCacheAlgol(cacheType string, limit int) (memcache.Cache, error) {
	switch cacheType {
	case LRUCache:
		return memcache.CreateLRUCache(limit), nil
	case Empty:
		return nil, errors.New("You need to specify a cache strategy")
	default:
		return nil, errors.New("Unknown cache strategy")
	}
}
package main

import (
	"fmt"
	"github.com/seanjohnno/memcache"
	"io/ioutil"
	"net/http"
)

var (
	Cache    = memcache.CreateLRUCache(1024 * 4)
	Resource = "https://raw.githubusercontent.com/seanjohnno/goexamples/master/helloworld.txt"
)

func main() {
	fileContent, _ := GetHttpData(Resource)
	fmt.Println("Content:", string(fileContent))

	fileContent, _ = GetHttpData(Resource)
	fmt.Println("Content:", string(fileContent))
}

type HttpContent struct {
	Content []byte
}

func (this *HttpContent) Size() int {
	return len(this.Content)
}

func GetHttpData(URI string) ([]byte, error) {