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
79f60274
Commit
79f60274
authored
Jun 15, 2017
by
moqiancong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix cache/memory fatal error: concurrent map iteration and map write
parent
d1c3bd84
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
13 deletions
+18
-13
memory.go
cache/memory.go
+18
-13
No files found.
cache/memory.go
View file @
79f60274
...
...
@@ -217,26 +217,31 @@ func (bc *MemoryCache) vaccuum() {
if
bc
.
items
==
nil
{
return
}
for
name
:=
range
bc
.
items
{
bc
.
itemExpired
(
name
)
if
keys
:=
bc
.
expiredKeys
();
len
(
keys
)
!=
0
{
bc
.
clearItems
(
keys
)
}
}
}
// itemExpired returns true if an item is expired.
func
(
bc
*
MemoryCache
)
itemExpired
(
name
string
)
bool
{
// expiredKeys returns key list which are expired.
func
(
bc
*
MemoryCache
)
expiredKeys
()
(
keys
[]
string
)
{
bc
.
RLock
()
defer
bc
.
RUnlock
()
for
key
,
itm
:=
range
bc
.
items
{
if
itm
.
isExpire
()
{
keys
=
append
(
keys
,
key
)
}
}
return
}
// clearItems removes all the items which key in keys.
func
(
bc
*
MemoryCache
)
clearItems
(
keys
[]
string
)
{
bc
.
Lock
()
defer
bc
.
Unlock
()
itm
,
ok
:=
bc
.
items
[
name
]
if
!
ok
{
return
true
for
_
,
key
:=
range
keys
{
delete
(
bc
.
items
,
key
)
}
if
itm
.
isExpire
()
{
delete
(
bc
.
items
,
name
)
return
true
}
return
false
}
func
init
()
{
...
...
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