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
Package registry
Container Registry
Model registry
Operate
Terraform modules
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
Timo Ley
synapse
Commits
d12c00bd
Commit
d12c00bd
authored
9 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Add some docstring explaining the snapshot cache does
parent
7fa71e32
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/snapshot_cache.py
+23
-1
23 additions, 1 deletion
synapse/util/caches/snapshot_cache.py
with
23 additions
and
1 deletion
synapse/util/caches/snapshot_cache.py
+
23
−
1
View file @
d12c00bd
...
@@ -17,8 +17,28 @@ from synapse.util.async import ObservableDeferred
...
@@ -17,8 +17,28 @@ from synapse.util.async import ObservableDeferred
class
SnapshotCache
(
object
):
class
SnapshotCache
(
object
):
"""
Cache for snapshots like the response of /initialSync.
The response of initialSync only has to be a recent snapshot of the
server state. It shouldn
'
t matter to clients if it is a few minutes out
of date.
DURATION_MS
=
5
*
60
*
1000
# Cache results for 2 minutes.
This caches a deferred response. Until the deferred completes it will be
returned from the cache. This means that if the client retries the request
while the response is still being computed, that original response will be
used rather than trying to compute a new response.
Once the deferred completes it will removed from the cache after 5 minutes.
We delay removing it from the cache because a client retrying its request
could race with us finishing computing the response.
Rather than tracking precisely how long something has been in the cache we
keep two generations of completed responses. Every 5 minutes discard the
old generation, move the new generation to the old generation, and set the
new generation to be empty. This means that a result will be in the cache
somewhere between 5 and 10 minutes.
"""
DURATION_MS
=
5
*
60
*
1000
# Cache results for 5 minutes.
def
__init__
(
self
):
def
__init__
(
self
):
self
.
pending_result_cache
=
{}
# Request that haven't finished yet.
self
.
pending_result_cache
=
{}
# Request that haven't finished yet.
...
@@ -51,6 +71,8 @@ class SnapshotCache(object):
...
@@ -51,6 +71,8 @@ class SnapshotCache(object):
result
=
self
.
pending_result_cache
.
get
(
key
,
result
)
result
=
self
.
pending_result_cache
.
get
(
key
,
result
)
if
result
is
not
None
:
if
result
is
not
None
:
return
result
.
observe
()
return
result
.
observe
()
else
:
return
None
def
set
(
self
,
time_now_ms
,
key
,
deferred
):
def
set
(
self
,
time_now_ms
,
key
,
deferred
):
self
.
rotate
(
time_now_ms
)
self
.
rotate
(
time_now_ms
)
...
...
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