Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
01f282c8b2e7
Commit
3a994ea4
authored
Nov 30, 2017
by
Brett Walker
Committed by
Stan Hu
Nov 30, 2017
Browse files
allow caching options to be specified for counting services
parent
58d49fcfdb40
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/services/base_count_service.rb
View file @
01f282c8
...
...
@@ -9,7 +9,7 @@ def relation_for_count
end
def
count
Rails
.
cache
.
fetch
(
cache_key
,
raw:
raw?
)
{
uncached_count
}.
to_i
Rails
.
cache
.
fetch
(
cache_key
,
cache_options
)
{
uncached_count
}.
to_i
end
def
refresh_cache
...
...
@@ -31,4 +31,10 @@ def raw?
def
cache_key
raise
NotImplementedError
,
'cache_key must be implemented and return a String'
end
# subclasses can override to add any specific options, such as
# super.merge({ expires_in: 5.minutes })
def
cache_options
{
raw:
raw?
}
end
end
spec/services/base_count_service_spec.rb
View file @
01f282c8
...
...
@@ -77,4 +77,10 @@
expect
{
service
.
cache_key
}.
to
raise_error
(
NotImplementedError
)
end
end
describe
'#cache_options'
do
it
'returns the default in options'
do
expect
(
service
.
cache_options
).
to
eq
({
raw:
false
})
end
end
end
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