Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
278d6c05
Commit
278d6c05
authored
9 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Report size of ExpiringCache
parent
b5f77eb1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/util/caches/expiringcache.py
+13
-2
13 additions, 2 deletions
synapse/util/caches/expiringcache.py
with
13 additions
and
2 deletions
synapse/util/caches/expiringcache.py
+
13
−
2
View file @
278d6c05
...
@@ -13,6 +13,8 @@
...
@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
from
synapse.util.caches
import
cache_counter
,
caches_by_name
import
logging
import
logging
...
@@ -47,6 +49,8 @@ class ExpiringCache(object):
...
@@ -47,6 +49,8 @@ class ExpiringCache(object):
self
.
_cache
=
{}
self
.
_cache
=
{}
caches_by_name
[
cache_name
]
=
self
.
_cache
def
start
(
self
):
def
start
(
self
):
if
not
self
.
_expiry_ms
:
if
not
self
.
_expiry_ms
:
# Don't bother starting the loop if things never expire
# Don't bother starting the loop if things never expire
...
@@ -72,7 +76,11 @@ class ExpiringCache(object):
...
@@ -72,7 +76,11 @@ class ExpiringCache(object):
self
.
_cache
.
pop
(
k
)
self
.
_cache
.
pop
(
k
)
def
__getitem__
(
self
,
key
):
def
__getitem__
(
self
,
key
):
entry
=
self
.
_cache
[
key
]
try
:
entry
=
self
.
_cache
[
key
]
cache_counter
.
inc_hits
(
self
.
_cache_name
)
finally
:
cache_counter
.
inc_misses
(
self
.
_cache_name
)
if
self
.
_reset_expiry_on_get
:
if
self
.
_reset_expiry_on_get
:
entry
.
time
=
self
.
_clock
.
time_msec
()
entry
.
time
=
self
.
_clock
.
time_msec
()
...
@@ -105,9 +113,12 @@ class ExpiringCache(object):
...
@@ -105,9 +113,12 @@ class ExpiringCache(object):
logger
.
debug
(
logger
.
debug
(
"
[%s] _prune_cache before: %d, after len: %d
"
,
"
[%s] _prune_cache before: %d, after len: %d
"
,
self
.
_cache_name
,
begin_length
,
len
(
self
.
_cache
.
keys
()
)
self
.
_cache_name
,
begin_length
,
len
(
self
.
_cache
)
)
)
def
__len__
(
self
):
return
len
(
self
.
_cache
)
class
_CacheEntry
(
object
):
class
_CacheEntry
(
object
):
def
__init__
(
self
,
time
,
value
):
def
__init__
(
self
,
time
,
value
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment