func (c *Cache) Set(key string, value interface{}, size int64) {
	c.Lock()
	defer c.Unlock()
	var it *Item
	elem, ok := c.m[key]
	if ok {
		it = elem.Value.(*Item)
		c.size -= it.Size
		c.l.MoveToFront(elem)
	} else {
		it = &Item{Key: key}
		elem = c.l.PushFront(it)
		c.m[key] = elem
	}
	it.Value = value
	it.Size = size
	if it.Size < 0 {
		panic("cache: value has negative size")
	}
	it.ModTime = time.Now()
	it.AccessTime = it.ModTime
	if it.Size >= math.MaxInt64-c.size {
		panic("cache: value size is too big")
	}
	c.size += it.Size
	c.enforceCapacity()
}
Set sets or updates a cache item for the given key to the given value,
and the given value size in bytes.
package cache
import (
	"container/list"
	"math"
	"sync"
	"time"
)
type Cache struct {
	sync.Mutex
	m map[string]*list.Element
	l *list.List
	size int64
	config Config
}
type Config struct {
	MaxItems int
	MaxBytes int64
	TrackAccessTime bool
	Expires time.Duration
	RemoveHandler func(Item)
}
type Item struct {
	Key        string
	Value      interface{}
	Size       int64      
	ModTime    time.Time  
	AccessTime time.Time  
}
func New(config Config) *Cache {
	return &Cache{
		m:      make(map[string]*list.Element, config.MaxItems),
		l:      list.New(),
		config: config,
	}
}
func (c *Cache) Reset() {
	c.Lock()
	defer c.Unlock()
	c.m = make(map[string]*list.Element, c.config.MaxItems)
	c.l.Init()
	c.size = 0
}
func (c *Cache) enforceCapacity() {
	if c.config.MaxItems > 0 {
		for c.l.Len() > c.config.MaxItems {
			if !c.dropTail() {
				break
			}
		}
	}
	if c.config.MaxBytes > 0 {
		for c.size > c.config.MaxBytes {
			if !c.dropTail() {
				break
			}
		}
	}
}