Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
121b3882
Commit
121b3882
authored
Dec 15, 2017
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Plain Diff
Merge "client: fix accounting of cache size"
parents
f2070ca4
5b02f44b
Changes
1
Hide 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 @
121b3882
...
@@ -135,13 +135,16 @@ class ClientCache(object):
...
@@ -135,13 +135,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
:
...
@@ -176,6 +179,7 @@ class ClientCache(object):
...
@@ -176,6 +179,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
...
@@ -260,6 +264,7 @@ class ClientCache(object):
...
@@ -260,6 +264,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
...
@@ -281,6 +286,8 @@ class ClientCache(object):
...
@@ -281,6 +286,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
...
@@ -307,10 +314,13 @@ def test(self):
...
@@ -307,10 +314,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
)
...
@@ -322,8 +332,10 @@ def test(self):
...
@@ -322,8 +332,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