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
0ff058bd
Commit
0ff058bd
authored
Jul 11, 2014
by
fuxiaohei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code style simplify
parent
0b1b121d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
14 deletions
+10
-14
memory.go
cache/memory.go
+10
-14
No files found.
cache/memory.go
View file @
0ff058bd
...
...
@@ -49,15 +49,14 @@ func NewMemoryCache() *MemoryCache {
func
(
bc
*
MemoryCache
)
Get
(
name
string
)
interface
{}
{
bc
.
lock
.
RLock
()
defer
bc
.
lock
.
RUnlock
()
itm
,
ok
:=
bc
.
items
[
name
]
if
!
ok
{
return
nil
}
if
(
time
.
Now
()
.
Unix
()
-
itm
.
Lastaccess
.
Unix
())
>
itm
.
expired
{
go
bc
.
Delete
(
name
)
return
nil
if
itm
,
ok
:=
bc
.
items
[
name
];
ok
{
if
(
time
.
Now
()
.
Unix
()
-
itm
.
Lastaccess
.
Unix
())
>
itm
.
expired
{
go
bc
.
Delete
(
name
)
return
nil
}
return
itm
.
val
}
return
itm
.
va
l
return
ni
l
}
// Put cache to memory.
...
...
@@ -65,12 +64,11 @@ func (bc *MemoryCache) Get(name string) interface{} {
func
(
bc
*
MemoryCache
)
Put
(
name
string
,
value
interface
{},
expired
int64
)
error
{
bc
.
lock
.
Lock
()
defer
bc
.
lock
.
Unlock
()
t
:=
MemoryItem
{
bc
.
items
[
name
]
=
&
MemoryItem
{
val
:
value
,
Lastaccess
:
time
.
Now
(),
expired
:
expired
,
}
bc
.
items
[
name
]
=
&
t
return
nil
}
...
...
@@ -82,8 +80,7 @@ func (bc *MemoryCache) Delete(name string) error {
return
errors
.
New
(
"key not exist"
)
}
delete
(
bc
.
items
,
name
)
_
,
valid
:=
bc
.
items
[
name
]
if
valid
{
if
_
,
ok
:=
bc
.
items
[
name
];
ok
{
return
errors
.
New
(
"delete key error"
)
}
return
nil
...
...
@@ -214,8 +211,7 @@ func (bc *MemoryCache) item_expired(name string) bool {
if
!
ok
{
return
true
}
sec
:=
time
.
Now
()
.
Unix
()
-
itm
.
Lastaccess
.
Unix
()
if
sec
>=
itm
.
expired
{
if
time
.
Now
()
.
Unix
()
-
itm
.
Lastaccess
.
Unix
()
>=
itm
.
expired
{
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