Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c615cb06
Unverified
Commit
c615cb06
authored
Feb 12, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Feb 12, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #73793 from tedyu/master
Reduce the duration where expirationLock is held for expiration_cache
parents
ff504cd8
4e3fd13a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
7 deletions
+7
-7
expiration_cache.go
staging/src/k8s.io/client-go/tools/cache/expiration_cache.go
+7
-7
No files found.
staging/src/k8s.io/client-go/tools/cache/expiration_cache.go
View file @
c615cb06
...
@@ -144,13 +144,13 @@ func (c *ExpirationCache) ListKeys() []string {
...
@@ -144,13 +144,13 @@ func (c *ExpirationCache) ListKeys() []string {
// Add timestamps an item and inserts it into the cache, overwriting entries
// Add timestamps an item and inserts it into the cache, overwriting entries
// that might exist under the same key.
// that might exist under the same key.
func
(
c
*
ExpirationCache
)
Add
(
obj
interface
{})
error
{
func
(
c
*
ExpirationCache
)
Add
(
obj
interface
{})
error
{
c
.
expirationLock
.
Lock
()
defer
c
.
expirationLock
.
Unlock
()
key
,
err
:=
c
.
keyFunc
(
obj
)
key
,
err
:=
c
.
keyFunc
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
KeyError
{
obj
,
err
}
return
KeyError
{
obj
,
err
}
}
}
c
.
expirationLock
.
Lock
()
defer
c
.
expirationLock
.
Unlock
()
c
.
cacheStorage
.
Add
(
key
,
&
timestampedEntry
{
obj
,
c
.
clock
.
Now
()})
c
.
cacheStorage
.
Add
(
key
,
&
timestampedEntry
{
obj
,
c
.
clock
.
Now
()})
return
nil
return
nil
}
}
...
@@ -163,12 +163,12 @@ func (c *ExpirationCache) Update(obj interface{}) error {
...
@@ -163,12 +163,12 @@ func (c *ExpirationCache) Update(obj interface{}) error {
// Delete removes an item from the cache.
// Delete removes an item from the cache.
func
(
c
*
ExpirationCache
)
Delete
(
obj
interface
{})
error
{
func
(
c
*
ExpirationCache
)
Delete
(
obj
interface
{})
error
{
c
.
expirationLock
.
Lock
()
defer
c
.
expirationLock
.
Unlock
()
key
,
err
:=
c
.
keyFunc
(
obj
)
key
,
err
:=
c
.
keyFunc
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
KeyError
{
obj
,
err
}
return
KeyError
{
obj
,
err
}
}
}
c
.
expirationLock
.
Lock
()
defer
c
.
expirationLock
.
Unlock
()
c
.
cacheStorage
.
Delete
(
key
)
c
.
cacheStorage
.
Delete
(
key
)
return
nil
return
nil
}
}
...
@@ -177,8 +177,6 @@ func (c *ExpirationCache) Delete(obj interface{}) error {
...
@@ -177,8 +177,6 @@ func (c *ExpirationCache) Delete(obj interface{}) error {
// before attempting the replace operation. The replace operation will
// before attempting the replace operation. The replace operation will
// delete the contents of the ExpirationCache `c`.
// delete the contents of the ExpirationCache `c`.
func
(
c
*
ExpirationCache
)
Replace
(
list
[]
interface
{},
resourceVersion
string
)
error
{
func
(
c
*
ExpirationCache
)
Replace
(
list
[]
interface
{},
resourceVersion
string
)
error
{
c
.
expirationLock
.
Lock
()
defer
c
.
expirationLock
.
Unlock
()
items
:=
make
(
map
[
string
]
interface
{},
len
(
list
))
items
:=
make
(
map
[
string
]
interface
{},
len
(
list
))
ts
:=
c
.
clock
.
Now
()
ts
:=
c
.
clock
.
Now
()
for
_
,
item
:=
range
list
{
for
_
,
item
:=
range
list
{
...
@@ -188,6 +186,8 @@ func (c *ExpirationCache) Replace(list []interface{}, resourceVersion string) er
...
@@ -188,6 +186,8 @@ func (c *ExpirationCache) Replace(list []interface{}, resourceVersion string) er
}
}
items
[
key
]
=
&
timestampedEntry
{
item
,
ts
}
items
[
key
]
=
&
timestampedEntry
{
item
,
ts
}
}
}
c
.
expirationLock
.
Lock
()
defer
c
.
expirationLock
.
Unlock
()
c
.
cacheStorage
.
Replace
(
items
,
resourceVersion
)
c
.
cacheStorage
.
Replace
(
items
,
resourceVersion
)
return
nil
return
nil
}
}
...
...
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