Commit df000f03 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'add-default-reactive-cache-key' into 'master'

Add a default reactive cache key

See merge request gitlab-org/gitlab-ce!29337
parents c7c960cc 63b0c730
...@@ -8,7 +8,6 @@ module Clusters ...@@ -8,7 +8,6 @@ module Clusters
include ReactiveCaching include ReactiveCaching
self.table_name = 'clusters' self.table_name = 'clusters'
self.reactive_cache_key = -> (cluster) { [cluster.class.model_name.singular, cluster.id] }
PROJECT_ONLY_APPLICATIONS = { PROJECT_ONLY_APPLICATIONS = {
Applications::Jupyter.application_name => Applications::Jupyter, Applications::Jupyter.application_name => Applications::Jupyter,
......
...@@ -11,7 +11,6 @@ module Clusters ...@@ -11,7 +11,6 @@ module Clusters
RESERVED_NAMESPACES = %w(gitlab-managed-apps).freeze RESERVED_NAMESPACES = %w(gitlab-managed-apps).freeze
self.table_name = 'cluster_platforms_kubernetes' self.table_name = 'cluster_platforms_kubernetes'
self.reactive_cache_key = ->(kubernetes) { [kubernetes.class.model_name.singular, kubernetes.id] }
belongs_to :cluster, inverse_of: :platform_kubernetes, class_name: 'Clusters::Cluster' belongs_to :cluster, inverse_of: :platform_kubernetes, class_name: 'Clusters::Cluster'
......
...@@ -6,7 +6,6 @@ module PrometheusAdapter ...@@ -6,7 +6,6 @@ module PrometheusAdapter
included do included do
include ReactiveCaching include ReactiveCaching
self.reactive_cache_key = ->(adapter) { [adapter.class.model_name.singular, adapter.id] }
self.reactive_cache_lease_timeout = 30.seconds self.reactive_cache_lease_timeout = 30.seconds
self.reactive_cache_refresh_interval = 30.seconds self.reactive_cache_refresh_interval = 30.seconds
self.reactive_cache_lifetime = 1.minute self.reactive_cache_lifetime = 1.minute
......
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
# class Foo < ApplicationRecord # class Foo < ApplicationRecord
# include ReactiveCaching # include ReactiveCaching
# #
# self.reactive_cache_key = ->(thing) { ["foo", thing.id] }
#
# after_save :clear_reactive_cache! # after_save :clear_reactive_cache!
# #
# def calculate_reactive_cache # def calculate_reactive_cache
...@@ -89,6 +87,8 @@ module ReactiveCaching ...@@ -89,6 +87,8 @@ module ReactiveCaching
class_attribute :reactive_cache_worker_finder class_attribute :reactive_cache_worker_finder
# defaults # defaults
self.reactive_cache_key = -> (record) { [model_name.singular, record.id] }
self.reactive_cache_lease_timeout = 2.minutes self.reactive_cache_lease_timeout = 2.minutes
self.reactive_cache_refresh_interval = 1.minute self.reactive_cache_refresh_interval = 1.minute
......
...@@ -232,4 +232,17 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do ...@@ -232,4 +232,17 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
end end
end end
end end
describe 'default options' do
let(:cached_class) { Class.new { include ReactiveCaching } }
subject { cached_class.new }
it { expect(subject.reactive_cache_lease_timeout).to be_a(ActiveSupport::Duration) }
it { expect(subject.reactive_cache_refresh_interval).to be_a(ActiveSupport::Duration) }
it { expect(subject.reactive_cache_lifetime).to be_a(ActiveSupport::Duration) }
it { expect(subject.reactive_cache_key).to respond_to(:call) }
it { expect(subject.reactive_cache_worker_finder).to respond_to(:call) }
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment