Module: ArtirixDataModels::CacheService
- Defined in:
- lib/artirix_data_models/cache_service.rb
Class Method Summary collapse
- .digest_element(element) ⇒ Object
-
.expire_cache(pattern = nil, add_wildcard: true, add_prefix: true) ⇒ Object
we use ‘delete_matched` method -> it will work fine with Redis but it seems that it won’t with Memcached.
- .final_pattern(pattern, add_wildcard: true, add_prefix: true) ⇒ Object
- .first_options(*options, return_if_missing: :default, **opts) ⇒ Object
- .key(*given_args) ⇒ Object
- .method_missing(m, *args, &block) ⇒ Object
- .options(options_name) ⇒ Object
- .options?(options_name) ⇒ Boolean
- .reload_service ⇒ Object
- .respond_to_missing?(m, include_all = false) ⇒ Boolean
- .service ⇒ Object
Class Method Details
.digest_element(element) ⇒ Object
28 29 30 |
# File 'lib/artirix_data_models/cache_service.rb', line 28 def self.digest_element(element) service.digest element end |
.expire_cache(pattern = nil, add_wildcard: true, add_prefix: true) ⇒ Object
we use ‘delete_matched` method -> it will work fine with Redis but it seems that it won’t with Memcached
54 55 56 57 58 59 60 |
# File 'lib/artirix_data_models/cache_service.rb', line 54 def self.expire_cache(pattern = nil, add_wildcard: true, add_prefix: true) return false unless ArtirixDataModels.cache.present? p = final_pattern(pattern, add_wildcard: add_wildcard, add_prefix: add_prefix) ArtirixDataModels.cache.delete_matched p end |
.final_pattern(pattern, add_wildcard: true, add_prefix: true) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/artirix_data_models/cache_service.rb', line 62 def self.final_pattern(pattern, add_wildcard: true, add_prefix: true) p = pattern p = p.present? ? "#{p}*" : '' if add_wildcard p = "*#{service.key_prefix}*#{p}" if add_prefix p end |
.first_options(*options, return_if_missing: :default, **opts) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/artirix_data_models/cache_service.rb', line 32 def self.(*, return_if_missing: :default, **opts) if opts.key? :return_if_none ActiveSupport::Deprecation.warn('use `return_if_missing` instead of `return_if_none`') return_if_missing = opts[:return_if_none] end service. *, return_if_missing: return_if_missing end |
.key(*given_args) ⇒ Object
41 42 43 |
# File 'lib/artirix_data_models/cache_service.rb', line 41 def self.key(*given_args) service.key *given_args end |
.method_missing(m, *args, &block) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/artirix_data_models/cache_service.rb', line 70 def self.method_missing(m, *args, &block) method = m.to_s if method.end_with? '_key' ActiveSupport::Deprecation.warn('using method_missing with `service.some_key("1", "2")` is deprecated, use this instead: `service.key(:some, "1", "2")`') key = method.gsub(/_key$/, '') self.key key, *args elsif method.end_with? '_options' ActiveSupport::Deprecation.warn('using method_missing with `service.some_options` is deprecated, use this instead: `service.options(:some)`') = method.gsub(/_options$/, '') self. else super end end |
.options(options_name) ⇒ Object
45 46 47 |
# File 'lib/artirix_data_models/cache_service.rb', line 45 def self.() service. end |
.options?(options_name) ⇒ Boolean
49 50 51 |
# File 'lib/artirix_data_models/cache_service.rb', line 49 def self.() service. end |
.reload_service ⇒ Object
2 3 4 5 |
# File 'lib/artirix_data_models/cache_service.rb', line 2 def self.reload_service @service = nil service end |
.respond_to_missing?(m, include_all = false) ⇒ Boolean
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/artirix_data_models/cache_service.rb', line 88 def self.respond_to_missing?(m, include_all = false) method = m.to_s if method.end_with? '_key' ActiveSupport::Deprecation.warn('using method_missing with `service.some_key("1", "2")` is deprecated, use this instead: `service.key(:some, "1", "2")`') true elsif method.end_with? '_options' ActiveSupport::Deprecation.warn('using method_missing with `service.some_options` is deprecated, use this instead: `service.options(:some)`') = method.gsub(/_options$/, '') self. else super end end |
.service ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/artirix_data_models/cache_service.rb', line 7 def self.service @service ||= ArtirixCacheService::Service.new.tap do |service| prefix = ArtirixDataModels.configuration.try(:cache_app_prefix) if prefix service.register_key_prefix "#{prefix}__" end = ArtirixDataModels.configuration.try(:cache_options) if .each do |name, opts| if name.to_s == 'default_options' service. opts else service. name, opts end end end end end |