Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
ecc1a831
Commit
ecc1a831
authored
Apr 24, 2001
by
Shane Hathaway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added "max_age" parameter to RAM cache manager, making it easier to
configure for certain kinds of setups.
parent
62c36ef8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
8 deletions
+54
-8
lib/python/Products/StandardCacheManagers/RAMCacheManager.py
lib/python/Products/StandardCacheManagers/RAMCacheManager.py
+37
-3
lib/python/Products/StandardCacheManagers/dtml/propsRCM.dtml
lib/python/Products/StandardCacheManagers/dtml/propsRCM.dtml
+16
-4
lib/python/Products/StandardCacheManagers/version.txt
lib/python/Products/StandardCacheManagers/version.txt
+1
-1
No files found.
lib/python/Products/StandardCacheManagers/RAMCacheManager.py
View file @
ecc1a831
...
...
@@ -127,6 +127,7 @@ class CacheEntry:
self
.
size
=
len
(
dumps
(
index
))
+
len
(
dumps
(
data
))
except
:
raise
CacheException
(
'The data for the cache is not pickleable.'
)
self
.
created
=
time
.
time
()
self
.
data
=
data
self
.
view_name
=
view_name
self
.
access_count
=
0
...
...
@@ -142,7 +143,7 @@ class ObjectCacheEntries:
def
__init__
(
self
,
path
):
self
.
physical_path
=
path
self
.
lastmod
=
0
self
.
lastmod
=
0
# Mod time of the object, class, etc.
self
.
entries
=
{}
def
aggregateIndex
(
self
,
view_name
,
req
,
req_names
,
local_keys
):
...
...
@@ -181,6 +182,10 @@ class ObjectCacheEntries:
self
.
lastmod
=
lastmod
self
.
entries
[
index
]
=
CacheEntry
(
index
,
data
,
view_name
)
def
delEntry
(
self
,
index
):
try
:
del
self
.
entries
[
index
]
except
KeyError
:
pass
class
RAMCache
(
Cache
):
# Note the need to take thread safety into account.
...
...
@@ -258,10 +263,27 @@ class RAMCache (Cache):
finally
:
self
.
writelock
.
release
()
def
deleteStaleEntries
(
self
):
"""
Deletes entries that have expired.
"""
self
.
writelock
.
acquire
()
try
:
min_created
=
time
.
time
()
-
self
.
max_age
for
p
,
oc
in
self
.
cache
.
items
():
for
agindex
,
entry
in
oc
.
entries
.
items
():
if
entry
.
created
<
min_created
:
del
oc
.
entries
[
agindex
]
if
len
(
oc
.
entries
)
<
1
:
del
self
.
cache
[
p
]
finally
:
self
.
writelock
.
release
()
def
cleanup
(
self
):
'''
Removes cache entries.
'''
self
.
deleteStaleEntries
()
new_count
=
self
.
countAllEntries
()
if
new_count
>
self
.
threshold
:
counters
=
self
.
countAccesses
()
...
...
@@ -334,6 +356,14 @@ class RAMCache (Cache):
entry
=
oc
.
getEntry
(
lastmod
,
index
)
if
entry
is
_marker
:
return
default
if
entry
.
created
<
time
.
time
()
-
self
.
max_age
:
# Expired.
self
.
writelock
.
acquire
()
try
:
oc
.
delEntry
(
index
)
finally
:
self
.
writelock
.
release
()
return
default
oc
.
hits
=
oc
.
hits
+
1
entry
.
access_count
=
entry
.
access_count
+
1
return
entry
.
data
...
...
@@ -389,7 +419,9 @@ class RAMCacheManager (CacheManager, SimpleItem):
self
.
_settings
=
{
'threshold'
:
1000
,
'cleanup_interval'
:
300
,
'request_vars'
:
(
'AUTHENTICATED_USER'
,)}
'request_vars'
:
(
'AUTHENTICATED_USER'
,),
'max_age'
:
3600
,
}
self
.
__cacheid
=
'%s_%f'
%
(
id
(
self
),
time
.
time
())
def
getId
(
self
):
...
...
@@ -423,7 +455,9 @@ class RAMCacheManager (CacheManager, SimpleItem):
self
.
_settings
=
{
'threshold'
:
int
(
settings
[
'threshold'
]),
'cleanup_interval'
:
int
(
settings
[
'cleanup_interval'
]),
'request_vars'
:
tuple
(
request_vars
)}
'request_vars'
:
tuple
(
request_vars
),
'max_age'
:
int
(
settings
[
'max_age'
]),
}
cache
=
self
.
ZCacheManager_getCache
()
cache
.
initSettings
(
self
.
_settings
)
if
REQUEST
is
not
None
:
...
...
lib/python/Products/StandardCacheManagers/dtml/propsRCM.dtml
View file @
ecc1a831
...
...
@@ -18,18 +18,19 @@
<tr>
<td align="left" valign="top">
<div class="form-label">
REQUEST
V
ariables
REQUEST
v
ariables
</div>
</td>
<td align="left" valign="top">
<textarea name="request_vars:lines" rows="5" cols="30"><dtml-in
request_vars>&dtml-sequence-item;</dtml-in></textarea>
request_vars>&dtml-sequence-item;
</dtml-in></textarea>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Threshold
E
ntries
Threshold
e
ntries
</div>
</td>
<td align="left" valign="top">
...
...
@@ -40,7 +41,18 @@
<tr>
<td align="left" valign="top">
<div class="form-label">
Cleanup Interval (Seconds)
Maximum age of a cache entry (seconds)
</div>
</td>
<td align="left" valign="top">
<input type="text" name="max_age" size="40"
value="&dtml-max_age;" />
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Cleanup interval (seconds)
</div>
</td>
<td align="left" valign="top">
...
...
lib/python/Products/StandardCacheManagers/version.txt
View file @
ecc1a831
StandardCacheManagers-1-
0
-0
StandardCacheManagers-1-
1
-0
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