Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
5b02f44b
Commit
5b02f44b
authored
Dec 13, 2017
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client: fix accounting of cache size
parent
03b5b47e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
3 deletions
+15
-3
neo/client/cache.py
neo/client/cache.py
+15
-3
No files found.
neo/client/cache.py
View file @
5b02f44b
...
@@ -127,13 +127,16 @@ class ClientCache(object):
...
@@ -127,13 +127,16 @@ class ClientCache(object):
if
level
:
if
level
:
item
.
expire
=
self
.
_time
+
self
.
_life_time
item
.
expire
=
self
.
_time
+
self
.
_life_time
else
:
else
:
self
.
_size
-=
len
(
item
.
data
)
self
.
_empty
(
item
)
item
.
data
=
None
self
.
_history_size
+=
1
self
.
_history_size
+=
1
if
self
.
_max_history_size
<
self
.
_history_size
:
if
self
.
_max_history_size
<
self
.
_history_size
:
self
.
_remove
(
head
)
self
.
_remove
(
head
)
self
.
_remove_from_oid_dict
(
head
)
self
.
_remove_from_oid_dict
(
head
)
def
_empty
(
self
,
item
):
self
.
_size
-=
len
(
item
.
data
)
item
.
data
=
None
def
_remove
(
self
,
item
):
def
_remove
(
self
,
item
):
level
=
item
.
level
level
=
item
.
level
if
level
is
not
None
:
if
level
is
not
None
:
...
@@ -168,6 +171,7 @@ class ClientCache(object):
...
@@ -168,6 +171,7 @@ class ClientCache(object):
if
head
.
level
or
head
.
counter
:
if
head
.
level
or
head
.
counter
:
self
.
_add
(
head
)
self
.
_add
(
head
)
else
:
else
:
self
.
_empty
(
head
)
self
.
_remove_from_oid_dict
(
head
)
self
.
_remove_from_oid_dict
(
head
)
break
break
...
@@ -250,6 +254,7 @@ class ClientCache(object):
...
@@ -250,6 +254,7 @@ class ClientCache(object):
head
.
level
=
0
head
.
level
=
0
self
.
_add
(
head
)
self
.
_add
(
head
)
else
:
else
:
self
.
_empty
(
head
)
self
.
_remove_from_oid_dict
(
head
)
self
.
_remove_from_oid_dict
(
head
)
if
self
.
_size
<=
max_size
:
if
self
.
_size
<=
max_size
:
return
return
...
@@ -271,6 +276,8 @@ class ClientCache(object):
...
@@ -271,6 +276,8 @@ class ClientCache(object):
for
oid
,
item_list
in
self
.
_oid_dict
.
items
():
for
oid
,
item_list
in
self
.
_oid_dict
.
items
():
item
=
item_list
[
-
1
]
item
=
item_list
[
-
1
]
if
item
.
next_tid
is
None
:
if
item
.
next_tid
is
None
:
if
item
.
level
:
self
.
_empty
(
item
)
self
.
_remove
(
item
)
self
.
_remove
(
item
)
del
item_list
[
-
1
]
del
item_list
[
-
1
]
# We don't preserve statistics of removed items. This could be
# We don't preserve statistics of removed items. This could be
...
@@ -297,10 +304,13 @@ def test(self):
...
@@ -297,10 +304,13 @@ def test(self):
cache
.
store
(
1
,
*
data
)
cache
.
store
(
1
,
*
data
)
self
.
assertEqual
(
cache
.
load
(
1
,
None
),
data
)
self
.
assertEqual
(
cache
.
load
(
1
,
None
),
data
)
cache
.
clear_current
()
cache
.
clear_current
()
self
.
assertEqual
(
cache
.
_size
,
1
)
self
.
assertEqual
(
cache
.
load
(
1
,
None
),
None
)
self
.
assertEqual
(
cache
.
load
(
1
,
None
),
None
)
cache
.
store
(
1
,
*
data
)
cache
.
store
(
1
,
*
data
)
cache
.
invalidate
(
1
,
20
)
cache
.
invalidate
(
1
,
20
)
self
.
assertEqual
(
cache
.
_size
,
3
)
cache
.
clear_current
()
cache
.
clear_current
()
self
.
assertEqual
(
cache
.
_size
,
3
)
self
.
assertEqual
(
cache
.
load
(
1
,
20
),
(
'15'
,
15
,
20
))
self
.
assertEqual
(
cache
.
load
(
1
,
20
),
(
'15'
,
15
,
20
))
cache
.
store
(
1
,
'10'
,
10
,
15
)
cache
.
store
(
1
,
'10'
,
10
,
15
)
cache
.
store
(
1
,
'20'
,
20
,
21
)
cache
.
store
(
1
,
'20'
,
20
,
21
)
...
@@ -312,8 +322,10 @@ def test(self):
...
@@ -312,8 +322,10 @@ def test(self):
cache
.
clear
()
cache
.
clear
()
cache
.
store
(
1
,
'10*'
,
10
,
None
)
cache
.
store
(
1
,
'10*'
,
10
,
None
)
cache
.
_max_size
=
cache
.
_size
cache
.
_max_size
=
cache
.
_size
cache
.
store
(
2
,
'10'
,
10
,
None
)
cache
.
store
(
2
,
'10'
,
10
,
15
)
self
.
assertEqual
(
cache
.
_queue_list
[
0
].
oid
,
1
)
self
.
assertEqual
(
cache
.
_queue_list
[
0
].
oid
,
1
)
cache
.
store
(
2
,
'15'
,
15
,
None
)
self
.
assertEqual
(
cache
.
_queue_list
[
2
].
oid
,
2
)
data
=
'10'
,
10
,
15
data
=
'10'
,
10
,
15
cache
.
store
(
1
,
*
data
)
cache
.
store
(
1
,
*
data
)
self
.
assertEqual
(
cache
.
load
(
1
,
15
),
data
)
self
.
assertEqual
(
cache
.
load
(
1
,
15
),
data
)
...
...
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