Method: YARD::Server::Commands::Base#cache

Defined in:
lib/yard/server/commands/base.rb

#cache(data) ⇒ String (protected)

Override this method to implement custom caching mechanisms for

Examples:

Caching to memory

$memory_cache = {}
def cache(data)
  $memory_cache[path] = data
end

Parameters:

  • data (String)

    the data to cache

Returns:

  • (String)

    the same cached data (for chaining)

See Also:

Since:

  • 0.6.0

[View source]

159
160
161
162
163
164
165
166
167
168
# File 'lib/yard/server/commands/base.rb', line 159

def cache(data)
  if caching && adapter.document_root
    path = File.join(adapter.document_root, request.path.sub(/\.html$/, '') + '.html')
    path = path.sub(%r{/\.html$}, '.html')
    FileUtils.mkdir_p(File.dirname(path))
    log.debug "Caching data to #{path}"
    File.open(path, 'wb') {|f| f.write(data) }
  end
  self.body = data
end