Sha256: baf4f32a85fa9ee2f08f95c1e6408e669b7cdf01a4711fa1800d34e7861b88c3
Contents?: true
Size: 1.08 KB
Versions: 1
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true module Aqila module Cache module Methods extend ActiveSupport::Concern included do def self.cache_ttl=(cache_ttl) @cache_ttl = cache_ttl end def self.cache_ttl @cache_ttl || Aqila::Cache.configuration.default_ttl end def self.update_log_table Aqila::Cache::TableLastChange .find_or_initialize_by(table_name: table_name) .update(updated_at: Time.current) end def self.stale?(controller:) check_ttl controller.response.headers['Cache-Control'] = 'public' controller.stale?(last_modified: Aqila::Cache::TableLastChange.for(model: self)) end def self.check_ttl return unless cache_ttl log_table = Aqila::Cache::TableLastChange.for(model: self) return update_log_table unless log_table expired = (Time.current - log_table) > cache_ttl update_log_table if expired end private_class_method :check_ttl end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
aqila-cache-0.3.0 | lib/aqila/cache/methods.rb |