Class: Customer::Cache::CustomerFilter

Inherits:
Object
  • Object
show all
Defined in:
app/services/customer/cache/customer_filter.rb

Overview

Facade to cache operations on customer
this way we don't have to hunt around for those cache key its all in one place

Class Method Summary collapse

Class Method Details

.cache_key(customer) ⇒ Object

Cache key for a customer and customer filter has to take into account
the customer cache key and also the last time customer filter were updated



7
8
9
# File 'app/services/customer/cache/customer_filter.rb', line 7

def self.cache_key(customer)
  [:customer_filter_ids, customer.cache_key, last_updated_filter_cache_key]
end

.fetch(customer) ⇒ Object



16
17
18
19
20
21
22
23
# File 'app/services/customer/cache/customer_filter.rb', line 16

def self.fetch(customer)
  if block_given?
    res = Rails.cache.fetch( cache_key(customer), expires_in: 1.week ) { yield }
  else
    res = Rails.cache.read( cache_key(customer) )
  end
  res.compact.uniq if res
end

.flush(customer) ⇒ Object



11
12
13
14
# File 'app/services/customer/cache/customer_filter.rb', line 11

def self.flush(customer)
  Rails.logger.info "[Customer::Cache::CustomerFilter] Cache Reset for customer #{customer.id}"
  Rails.cache.delete customer
end

.last_updated_filter_cache_keyObject



25
26
27
# File 'app/services/customer/cache/customer_filter.rb', line 25

def self.last_updated_filter_cache_key
  ::CustomerFilter.maximum(:updated_at).to_i
end