module Shibkit::MetaMeta::Mixin::CachedDownloads::CDClassMethods

Class methods to mixin to including class

Public Instance Methods

init_caches() click to toggle source

Create the web cache

# File lib/shibkit/meta_meta/mixin/cached_downloads.rb, line 84
def init_caches

  @initialised_caches ||= false

  ## Because these long class names are pain to keep typing
  config = ::Shibkit::MetaMeta.config

  unless @initialised_caches
    

    ## JIT loading of the Cache module so we can set options first
    RestClient.enable Rack::Cache, config.download_cache_options

    ## Allow user to write log of all downloads in a standard format
    if config.downloads_logger

      RestClient.enable Rack::CommonLogger, config.downloads_logger

    else

      RestClient.disable Rack::CommonLogger

    end


    @initialised_caches = true

  end
  
  ## Helps if the locations actually exist, of course.
  FileUtils.mkdir_p File.join(config.cache_root, 'meta')
  FileUtils.mkdir_p File.join(config.cache_root, 'body')
  
end