Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
8aed4c13
Commit
8aed4c13
authored
Jan 07, 2016
by
JessonChan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
isExist func will check if the value is expired
parent
6465dbd7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
+7
-5
memory.go
cache/memory.go
+7
-5
No files found.
cache/memory.go
View file @
8aed4c13
...
...
@@ -82,14 +82,14 @@ func (bc *MemoryCache) GetMulti(names []string) []interface{} {
}
// Put cache to memory.
// if
expired is 0, it will be cleaned by next gc operation ( default gc clock is 1 minute)
.
func
(
bc
*
MemoryCache
)
Put
(
name
string
,
value
interface
{},
expired
int64
)
error
{
// if
lifespan is 0, it will be forever till restart
.
func
(
bc
*
MemoryCache
)
Put
(
name
string
,
value
interface
{},
lifespan
int64
)
error
{
bc
.
Lock
()
defer
bc
.
Unlock
()
bc
.
items
[
name
]
=
&
MemoryItem
{
val
:
value
,
cratedTime
:
time
.
Now
(),
lifespan
:
expired
,
lifespan
:
lifespan
,
}
return
nil
}
...
...
@@ -179,8 +179,10 @@ func (bc *MemoryCache) Decr(key string) error {
func
(
bc
*
MemoryCache
)
IsExist
(
name
string
)
bool
{
bc
.
RLock
()
defer
bc
.
RUnlock
()
_
,
ok
:=
bc
.
items
[
name
]
return
ok
if
v
,
ok
:=
bc
.
items
[
name
];
ok
{
return
!
v
.
isExpire
()
}
return
false
}
// ClearAll will delete all cache in memory.
...
...
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