Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
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
Kirill Smelkov
ZODB
Commits
b82e898f
Commit
b82e898f
authored
Nov 19, 2008
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a method to clear the cache.
parent
8ef7056b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
3 deletions
+23
-3
src/ZEO/cache.py
src/ZEO/cache.py
+9
-3
src/ZEO/tests/test_cache.py
src/ZEO/tests/test_cache.py
+14
-0
No files found.
src/ZEO/cache.py
View file @
b82e898f
...
...
@@ -208,7 +208,7 @@ class ClientCache(object):
self
.
f
.
write
(
magic
+
z64
)
logger
.
info
(
"created temporary cache file %r"
,
self
.
f
.
name
)
self
.
_initfile
(
self
.
f
,
fsize
)
self
.
_initfile
(
fsize
)
# Statistics: _n_adds, _n_added_bytes,
# _n_evicts, _n_evicted_bytes,
...
...
@@ -225,18 +225,24 @@ class ClientCache(object):
def
fc
(
self
):
return
self
def
clear
(
self
):
self
.
f
.
seek
(
ZEC_HEADER_SIZE
)
self
.
f
.
truncate
()
self
.
_initfile
(
ZEC_HEADER_SIZE
)
##
# Scan the current contents of the cache file, calling `install`
# for each object found in the cache. This method should only
# be called once to initialize the cache from disk.
def
_initfile
(
self
,
f
,
f
size
):
def
_initfile
(
self
,
fsize
):
maxsize
=
self
.
maxsize
f
=
self
.
f
read
=
f
.
read
seek
=
f
.
seek
write
=
f
.
write
seek
(
0
)
if
read
(
4
)
!=
magic
:
raise
ValueError
(
"unexpected magic number: %r"
%
_
magic
)
raise
ValueError
(
"unexpected magic number: %r"
%
magic
)
self
.
tid
=
read
(
8
)
if
len
(
self
.
tid
)
!=
8
:
raise
ValueError
(
"cache file too small -- no tid at start"
)
...
...
src/ZEO/tests/test_cache.py
View file @
b82e898f
...
...
@@ -231,6 +231,20 @@ class CacheTests(ZODB.tests.util.TestCase):
# VM).
del
testVeryLargeCaches
del
testConversionOfLargeFreeBlocks
def
test_clear_zeo_cache
(
self
):
cache
=
self
.
cache
for
i
in
range
(
10
):
cache
.
store
(
p64
(
i
),
n2
,
None
,
str
(
i
))
cache
.
store
(
p64
(
i
),
n1
,
n2
,
str
(
i
)
+
'old'
)
self
.
assertEqual
(
len
(
cache
),
20
)
self
.
assertEqual
(
cache
.
load
(
n3
),
(
'3'
,
n2
))
self
.
assertEqual
(
cache
.
loadBefore
(
n3
,
n2
),
(
'3old'
,
n1
,
n2
))
cache
.
clear
()
self
.
assertEqual
(
len
(
cache
),
0
)
self
.
assertEqual
(
cache
.
load
(
n3
),
None
)
self
.
assertEqual
(
cache
.
loadBefore
(
n3
,
n2
),
None
)
def
testChangingCacheSize
(
self
):
# start with a small cache
...
...
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