mirror of
https://github.com/minio/minio.git
synced 2025-11-20 18:06:10 -05:00
Purge stale object cache entry (#2770)
This commit is contained in:
committed by
Harshavardhana
parent
27e474b3d2
commit
669783f875
@@ -163,7 +163,9 @@ func (c *Cache) Create(key string, size int64) (w io.WriteCloser, err error) {
|
||||
|
||||
// Open - open the in-memory file, returns an in memory read seeker.
|
||||
// returns an error ErrNotFoundInCache, if the key does not exist.
|
||||
func (c *Cache) Open(key string) (io.ReadSeeker, error) {
|
||||
// Returns ErrKeyNotFoundInCache if entry's lastAccessedTime is older
|
||||
// than objModTime.
|
||||
func (c *Cache) Open(key string, objModTime time.Time) (io.ReadSeeker, error) {
|
||||
// Entry exists, return the readable buffer.
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
@@ -171,6 +173,11 @@ func (c *Cache) Open(key string) (io.ReadSeeker, error) {
|
||||
if !ok {
|
||||
return nil, ErrKeyNotFoundInCache
|
||||
}
|
||||
// Check if buf is recent copy of the object on disk.
|
||||
if buf.lastAccessed.Before(objModTime) {
|
||||
c.delete(key)
|
||||
return nil, ErrKeyNotFoundInCache
|
||||
}
|
||||
buf.lastAccessed = time.Now().UTC()
|
||||
return bytes.NewReader(buf.value), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user