module YARD::Server::StaticCaching

def cache(data)

Other tags:
    Since: - 0.9.44

Returns:
  • (void) -

Parameters:
  • data (String) -- the data to cache
def cache(data)
  return unless adapter.document_root
  path = cache_path(request.path_info)
  return unless path
  FileUtils.mkdir_p(File.dirname(path))
  log.debug "Caching data to #{path}"
  File.open(path, 'wb') {|f| f.write(data) }
end

def cache_path(request_path)

def cache_path(request_path)
  return nil if request_path.split(/[\/\\]/).include?('..')
  path = request_path.sub(/\.html$/, '') + '.html'
  path = path.sub(%r{\A/+}, '')
  return nil if path =~ /\A[A-Za-z]:/
  path = File.cleanpath(path)
  File.join(adapter.document_root, path)
end

def check_static_cache

Other tags:
    See: Commands::Base#cache -

Returns:
  • (nil) - if no cache is available and routing should continue
  • (Array(Numeric,Hash,Array)) - the Rack-style response

Other tags:
    Example: Implementing In-Memory Cache Checking -
def check_static_cache
  return nil unless adapter.document_root
  cache_path = cache_path(request.path)
  return nil unless cache_path
  if File.file?(cache_path)
    log.debug "Loading cache from disk: #{cache_path}"
    return [200, {'Content-Type' => 'text/html'}, [File.read_binary(cache_path)]]
  end
  nil
end