github.com/wangyougui/gf/v2@v2.6.5/os/gcache/gcache_adapter_memory_expire_times.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/wangyougui/gf.
     6  
     7  package gcache
     8  
     9  import (
    10  	"sync"
    11  )
    12  
    13  type adapterMemoryExpireTimes struct {
    14  	mu          sync.RWMutex          // expireTimeMu ensures the concurrent safety of expireTimes map.
    15  	expireTimes map[interface{}]int64 // expireTimes is the expiring key to its timestamp mapping, which is used for quick indexing and deleting.
    16  }
    17  
    18  func newAdapterMemoryExpireTimes() *adapterMemoryExpireTimes {
    19  	return &adapterMemoryExpireTimes{
    20  		expireTimes: make(map[interface{}]int64),
    21  	}
    22  }
    23  
    24  func (d *adapterMemoryExpireTimes) Get(key interface{}) (value int64) {
    25  	d.mu.RLock()
    26  	value = d.expireTimes[key]
    27  	d.mu.RUnlock()
    28  	return
    29  }
    30  
    31  func (d *adapterMemoryExpireTimes) Set(key interface{}, value int64) {
    32  	d.mu.Lock()
    33  	d.expireTimes[key] = value
    34  	d.mu.Unlock()
    35  }
    36  
    37  func (d *adapterMemoryExpireTimes) Delete(key interface{}) {
    38  	d.mu.Lock()
    39  	delete(d.expireTimes, key)
    40  	d.mu.Unlock()
    41  }