mirror of
https://github.com/minio/minio.git
synced 2025-01-27 06:33:18 -05:00
Merge pull request #536 from fkautz/pr_out_expirations_are_now_based_on_last_accessed_instead_of_time_created
This commit is contained in:
commit
c718910300
@ -39,7 +39,7 @@ type MemoryFactory struct {
|
|||||||
// GetStartServerFunc builds memory api servers
|
// GetStartServerFunc builds memory api servers
|
||||||
func (f MemoryFactory) GetStartServerFunc() StartServerFunc {
|
func (f MemoryFactory) GetStartServerFunc() StartServerFunc {
|
||||||
return func() (chan<- string, <-chan error) {
|
return func() (chan<- string, <-chan error) {
|
||||||
_, _, driver := memory.Start(f.MaxMemory, 3*time.Hour)
|
_, _, driver := memory.Start(f.MaxMemory, 1*time.Hour)
|
||||||
ctrl, status, _ := httpserver.Start(api.HTTPHandler(f.Domain, driver), f.Config)
|
ctrl, status, _ := httpserver.Start(api.HTTPHandler(f.Domain, driver), f.Config)
|
||||||
return ctrl, status
|
return ctrl, status
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ package lru
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"container/list"
|
"container/list"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cache is an LRU cache. It is not safe for concurrent access.
|
// Cache is an LRU cache. It is not safe for concurrent access.
|
||||||
@ -48,6 +49,7 @@ type Cache struct {
|
|||||||
|
|
||||||
ll *list.List
|
ll *list.List
|
||||||
cache map[interface{}]*list.Element
|
cache map[interface{}]*list.Element
|
||||||
|
lock *sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators
|
// A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators
|
||||||
@ -66,11 +68,14 @@ func New(maxEntries int) *Cache {
|
|||||||
MaxEntries: maxEntries,
|
MaxEntries: maxEntries,
|
||||||
ll: list.New(),
|
ll: list.New(),
|
||||||
cache: make(map[interface{}]*list.Element),
|
cache: make(map[interface{}]*list.Element),
|
||||||
|
lock: &sync.RWMutex{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add adds a value to the cache.
|
// Add adds a value to the cache.
|
||||||
func (c *Cache) Add(key Key, value interface{}) {
|
func (c *Cache) Add(key Key, value interface{}) {
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
if c.cache == nil {
|
if c.cache == nil {
|
||||||
c.cache = make(map[interface{}]*list.Element)
|
c.cache = make(map[interface{}]*list.Element)
|
||||||
c.ll = list.New()
|
c.ll = list.New()
|
||||||
@ -89,6 +94,8 @@ func (c *Cache) Add(key Key, value interface{}) {
|
|||||||
|
|
||||||
// Get looks up a key's value from the cache.
|
// Get looks up a key's value from the cache.
|
||||||
func (c *Cache) Get(key Key) (value interface{}, ok bool) {
|
func (c *Cache) Get(key Key) (value interface{}, ok bool) {
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
if c.cache == nil {
|
if c.cache == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -101,6 +108,8 @@ func (c *Cache) Get(key Key) (value interface{}, ok bool) {
|
|||||||
|
|
||||||
// Remove removes the provided key from the cache.
|
// Remove removes the provided key from the cache.
|
||||||
func (c *Cache) Remove(key Key) {
|
func (c *Cache) Remove(key Key) {
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
if c.cache == nil {
|
if c.cache == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -111,6 +120,8 @@ func (c *Cache) Remove(key Key) {
|
|||||||
|
|
||||||
// RemoveOldest removes the oldest item from the cache.
|
// RemoveOldest removes the oldest item from the cache.
|
||||||
func (c *Cache) RemoveOldest() {
|
func (c *Cache) RemoveOldest() {
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
if c.cache == nil {
|
if c.cache == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -122,6 +133,8 @@ func (c *Cache) RemoveOldest() {
|
|||||||
|
|
||||||
// GetOldest returns the oldest key, value, ok without modifying the lru
|
// GetOldest returns the oldest key, value, ok without modifying the lru
|
||||||
func (c *Cache) GetOldest() (key Key, value interface{}, ok bool) {
|
func (c *Cache) GetOldest() (key Key, value interface{}, ok bool) {
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
if c.cache == nil {
|
if c.cache == nil {
|
||||||
return nil, nil, false
|
return nil, nil, false
|
||||||
}
|
}
|
||||||
@ -143,6 +156,8 @@ func (c *Cache) removeElement(e *list.Element) {
|
|||||||
|
|
||||||
// Len returns the number of items in the cache.
|
// Len returns the number of items in the cache.
|
||||||
func (c *Cache) Len() int {
|
func (c *Cache) Len() int {
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
if c.cache == nil {
|
if c.cache == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -123,6 +123,7 @@ func (memory *memoryDriver) GetObject(w io.Writer, bucket string, object string)
|
|||||||
dataSlice := data.([]byte)
|
dataSlice := data.([]byte)
|
||||||
objectBuffer := bytes.NewBuffer(dataSlice)
|
objectBuffer := bytes.NewBuffer(dataSlice)
|
||||||
written, err := io.Copy(w, objectBuffer)
|
written, err := io.Copy(w, objectBuffer)
|
||||||
|
go memory.updateAccessTime(objectKey)
|
||||||
return written, iodine.New(err, nil)
|
return written, iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,6 +283,7 @@ func (memory *memoryDriver) CreateObject(bucket, key, contentType, expectedMD5Su
|
|||||||
Md5: md5Sum,
|
Md5: md5Sum,
|
||||||
Size: int64(totalLength),
|
Size: int64(totalLength),
|
||||||
}
|
}
|
||||||
|
newObject.lastAccessed = time.Now()
|
||||||
memory.lock.Lock()
|
memory.lock.Lock()
|
||||||
if _, ok := memory.objectMetadata[objectKey]; ok == true {
|
if _, ok := memory.objectMetadata[objectKey]; ok == true {
|
||||||
memory.lock.Unlock()
|
memory.lock.Unlock()
|
||||||
@ -503,3 +505,12 @@ func (memory *memoryDriver) expireObjects() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (memory *memoryDriver) updateAccessTime(key string) {
|
||||||
|
memory.lock.Lock()
|
||||||
|
defer memory.lock.Unlock()
|
||||||
|
if object, ok := memory.objectMetadata[key]; ok {
|
||||||
|
object.lastAccessed = time.Now()
|
||||||
|
memory.objectMetadata[key] = object
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user