Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
c807a418
Commit
c807a418
authored
Jul 25, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport reactive caching
parent
6cb30f83
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
2 deletions
+15
-2
app/models/concerns/reactive_caching.rb
app/models/concerns/reactive_caching.rb
+8
-2
spec/models/concerns/reactive_caching_spec.rb
spec/models/concerns/reactive_caching_spec.rb
+7
-0
No files found.
app/models/concerns/reactive_caching.rb
View file @
c807a418
...
@@ -59,6 +59,9 @@ module ReactiveCaching
...
@@ -59,6 +59,9 @@ module ReactiveCaching
raise
NotImplementedError
raise
NotImplementedError
end
end
def
reactive_cache_updated
(
*
args
)
end
def
with_reactive_cache
(
*
args
,
&
blk
)
def
with_reactive_cache
(
*
args
,
&
blk
)
bootstrap
=
!
within_reactive_cache_lifetime?
(
*
args
)
bootstrap
=
!
within_reactive_cache_lifetime?
(
*
args
)
Rails
.
cache
.
write
(
alive_reactive_cache_key
(
*
args
),
true
,
expires_in:
self
.
class
.
reactive_cache_lifetime
)
Rails
.
cache
.
write
(
alive_reactive_cache_key
(
*
args
),
true
,
expires_in:
self
.
class
.
reactive_cache_lifetime
)
...
@@ -81,8 +84,11 @@ module ReactiveCaching
...
@@ -81,8 +84,11 @@ module ReactiveCaching
locking_reactive_cache
(
*
args
)
do
locking_reactive_cache
(
*
args
)
do
if
within_reactive_cache_lifetime?
(
*
args
)
if
within_reactive_cache_lifetime?
(
*
args
)
enqueuing_update
(
*
args
)
do
enqueuing_update
(
*
args
)
do
value
=
calculate_reactive_cache
(
*
args
)
key
=
full_reactive_cache_key
(
*
args
)
Rails
.
cache
.
write
(
full_reactive_cache_key
(
*
args
),
value
)
new_value
=
calculate_reactive_cache
(
*
args
)
old_value
=
Rails
.
cache
.
read
(
key
)
Rails
.
cache
.
write
(
key
,
new_value
)
reactive_cache_updated
(
*
args
)
if
new_value
!=
old_value
end
end
end
end
end
end
...
...
spec/models/concerns/reactive_caching_spec.rb
View file @
c807a418
...
@@ -125,6 +125,13 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
...
@@ -125,6 +125,13 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
go!
go!
end
end
it
"calls a reactive_cache_updated only once if content did not change on subsequent update"
do
expect
(
instance
).
to
receive
(
:calculate_reactive_cache
).
twice
expect
(
instance
).
to
receive
(
:reactive_cache_updated
).
once
2
.
times
{
instance
.
exclusively_update_reactive_cache!
}
end
context
'and #calculate_reactive_cache raises an exception'
do
context
'and #calculate_reactive_cache raises an exception'
do
before
do
before
do
stub_reactive_cache
(
instance
,
"preexisting"
)
stub_reactive_cache
(
instance
,
"preexisting"
)
...
...
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