Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
utils
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
golang kittool
utils
Commits
ff1bb7ab
Commit
ff1bb7ab
authored
May 13, 2022
by
feidy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change auto_gc_map public func
parent
551bae76
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
4 deletions
+24
-4
auto_gc_map.go
auto_gc_map.go
+12
-2
auto_gc_map_test.go
auto_gc_map_test.go
+12
-2
No files found.
auto_gc_map.go
View file @
ff1bb7ab
/*
* @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
)
s
et
(
key
string
,
data
interface
{},
ttl
int64
)
{
func
(
my
*
AutoGcMap
)
S
et
(
key
string
,
data
interface
{},
ttl
int64
)
{
my
.
lock
.
Lock
()
defer
my
.
lock
.
Unlock
()
my
.
data
[
key
]
=
newValue
(
data
,
ttl
)
}
func
(
my
*
AutoGcMap
)
g
et
(
key
string
)
(
interface
{},
bool
)
{
func
(
my
*
AutoGcMap
)
G
et
(
key
string
)
(
interface
{},
bool
)
{
my
.
lock
.
Lock
()
defer
my
.
lock
.
Unlock
()
if
value
,
ok
:=
my
.
data
[
key
];
ok
&&
value
.
alive
()
{
...
...
auto_gc_map_test.go
View file @
ff1bb7ab
/*
* @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
.
s
et
(
"a"
,
"b"
,
10
)
m
.
S
et
(
"a"
,
"b"
,
10
)
time
.
Sleep
(
10
*
time
.
Second
)
_
,
b
:=
m
.
g
et
(
"a"
)
_
,
b
:=
m
.
G
et
(
"a"
)
assert
.
Equal
(
t
,
b
,
false
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment