class AssetRam::Helper

Our own asset helper which memoizes Rails’ asset helper calls.

Public Class Methods

cache(key: '') { || ... } click to toggle source
# File lib/asset_ram.rb, line 33
def self.cache(key: '', &blk)
  return yield if ENV['ASSET_RAM_DISABLE']

  cache_key = blk.source_location
  cache_key << key if key.present?

  if !@@_cache.has_key?(cache_key)
    # Using WARN level because it should only be output
    # once during any Rails run. If its output multiple
    # times, then caching isn't working correctly.
    Rails.logger.warn("Caching #{cache_key}")
    @@_cache[cache_key] = yield
  end

  @@_cache.fetch(cache_key)
end