summaryrefslogtreecommitdiff
path: root/lib/feature/active_support_cache_store_adapter.rb
blob: 431f1169a86a015f874e8006ec0f5b3dac74f5e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

# rubocop:disable Gitlab/NamespacedClass
# This class was already nested this way before moving to a separate file
class Feature
  class ActiveSupportCacheStoreAdapter < Flipper::Adapters::ActiveSupportCacheStore
    # This patch represents https://github.com/jnunemaker/flipper/pull/512. In
    # Flipper 0.21.0 and later, we can remove this and just pass `write_through:
    # true` to the constructor in `Feature.build_flipper_instance`.

    extend ::Gitlab::Utils::Override

    override :enable
    def enable(feature, gate, thing)
      result = @adapter.enable(feature, gate, thing)
      @cache.write(key_for(feature.key), @adapter.get(feature), @write_options)
      result
    end

    override :disable
    def disable(feature, gate, thing)
      result = @adapter.disable(feature, gate, thing)
      @cache.write(key_for(feature.key), @adapter.get(feature), @write_options)
      result
    end

    override :remove
    def remove(feature)
      result = @adapter.remove(feature)
      @cache.delete(FeaturesKey)
      @cache.write(key_for(feature.key), {}, @write_options)
      result
    end
  end
end
# rubocop:disable Gitlab/NamespacedClass