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
b0b9812d
Commit
b0b9812d
authored
Jan 07, 2016
by
JessonChan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract a expire fun
parent
eff200e0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
6 deletions
+11
-6
memory.go
cache/memory.go
+11
-6
No files found.
cache/memory.go
View file @
b0b9812d
...
...
@@ -34,6 +34,14 @@ type MemoryItem struct {
expired
int64
}
func
(
mi
*
MemoryItem
)
isExpire
()
bool
{
// expired==0 means never
if
mi
.
expired
==
0
{
return
false
}
return
time
.
Now
()
.
Unix
()
-
mi
.
Lastaccess
.
Unix
()
>
mi
.
expired
}
// MemoryCache is Memory cache adapter.
// it contains a RW locker for safe map storage.
type
MemoryCache
struct
{
...
...
@@ -55,7 +63,7 @@ func (bc *MemoryCache) Get(name string) interface{} {
bc
.
RLock
()
defer
bc
.
RUnlock
()
if
itm
,
ok
:=
bc
.
items
[
name
];
ok
{
if
(
time
.
Now
()
.
Unix
()
-
itm
.
Lastaccess
.
Unix
())
>
itm
.
expired
{
if
itm
.
isExpire
()
{
go
bc
.
Delete
(
name
)
return
nil
}
...
...
@@ -222,15 +230,12 @@ func (bc *MemoryCache) vaccuum() {
func
(
bc
*
MemoryCache
)
itemExpired
(
name
string
)
bool
{
bc
.
Lock
()
defer
bc
.
Unlock
()
itm
,
ok
:=
bc
.
items
[
name
]
if
!
ok
{
return
true
}
// expired==0 means never
if
itm
.
expired
==
0
{
return
false
}
if
time
.
Now
()
.
Unix
()
-
itm
.
Lastaccess
.
Unix
()
>=
itm
.
expired
{
if
itm
.
isExpire
()
{
delete
(
bc
.
items
,
name
)
return
true
}
...
...
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