Module: YARD::Server::StaticCaching
- Included in:
- Router
- Defined in:
- lib/yard/server/static_caching.rb
Overview
Implements static caching for requests.
Instance Method Summary collapse
-
#check_static_cache ⇒ Array(Numeric,Hash,Array)?
Called by a router to return the cached object.
Instance Method Details
#check_static_cache ⇒ Array(Numeric,Hash,Array)?
Called by a router to return the cached object. By default, this method performs disk-based caching. To perform other forms of caching, implement your own #check_static_cache
method and mix the module into the Router class.
Note that caching does not occur here. This method simply checks for the existence of cached data. To actually cache a response, see Commands::Base#cache.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/yard/server/static_caching.rb', line 33 def check_static_cache return nil unless adapter.document_root cache_path = File.join(adapter.document_root, request.path.sub(/\.html$/, '') + '.html') cache_path = cache_path.sub(%r{/\.html$}, '.html') 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 |