Commit ff1bb7ab by feidy

change auto_gc_map public func

parent 551bae76
/*
* @Author: zhoufei
* @Date: 2022-04-06 10:18:28
* @LastEditors: zhoufei
* @LastEditTime: 2022-05-13 10:10:14
* @FilePath: /utils/auto_gc_map.go
* @Description:
*
* Copyright (c) 2022 by zhoufei, All Rights Reserved.
*/
package utils
import (
......@@ -40,13 +50,13 @@ func NewAutoGcMap() *AutoGcMap {
}
}
func (my *AutoGcMap) set(key string, data interface{}, ttl int64) {
func (my *AutoGcMap) Set(key string, data interface{}, ttl int64) {
my.lock.Lock()
defer my.lock.Unlock()
my.data[key] = newValue(data, ttl)
}
func (my *AutoGcMap) get(key string) (interface{}, bool) {
func (my *AutoGcMap) Get(key string) (interface{}, bool) {
my.lock.Lock()
defer my.lock.Unlock()
if value, ok := my.data[key]; ok && value.alive() {
......
/*
* @Author: zhoufei
* @Date: 2022-04-06 10:23:48
* @LastEditors: zhoufei
* @LastEditTime: 2022-05-13 10:10:27
* @FilePath: /utils/auto_gc_map_test.go
* @Description:
*
* Copyright (c) 2022 by zhoufei, All Rights Reserved.
*/
package utils
import (
......@@ -10,8 +20,8 @@ import (
func TestAutoGc(t *testing.T) {
m := NewAutoGcMap()
m.AutoGc(3)
m.set("a", "b", 10)
m.Set("a", "b", 10)
time.Sleep(10 * time.Second)
_, b := m.get("a")
_, b := m.Get("a")
assert.Equal(t, b, false)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment