Introduce a cache tied to individual sitemap pages. This helps individual extensions avoid having to implement methods to clear the cache whenever a page changes.
This commit is contained in:
parent
183e9d68f3
commit
4a4454fcab
3 changed files with 23 additions and 27 deletions
|
@ -113,18 +113,6 @@ module Middleman::Sitemap
|
|||
store.ignore(self.path)
|
||||
end
|
||||
|
||||
# If this is a template, refresh contents
|
||||
# @return [void]
|
||||
def touch
|
||||
template.touch if template?
|
||||
end
|
||||
|
||||
# If this is a template, remove contents
|
||||
# @return [void]
|
||||
def delete
|
||||
template.delete if template?
|
||||
end
|
||||
|
||||
# Render this page
|
||||
# @return [String]
|
||||
def render(*args, &block)
|
||||
|
@ -250,6 +238,26 @@ module Middleman::Sitemap
|
|||
return [] unless parent
|
||||
parent.children.reject { |p| p == self }
|
||||
end
|
||||
|
||||
# A cache for extensions and internals to use to store
|
||||
# information about this page. The cache is cleared whenever
|
||||
# the page changes.
|
||||
# @return [Middleman::Cache]
|
||||
def cache
|
||||
@cache ||= Middleman::Cache.new
|
||||
end
|
||||
|
||||
# Clear out the cache whenever this page changes
|
||||
# @return [void]
|
||||
def touch
|
||||
cache.clear
|
||||
end
|
||||
|
||||
# Clear the cache if the file is deleted
|
||||
# @return [void]
|
||||
def delete
|
||||
cache.clear
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
|
|
|
@ -31,22 +31,10 @@ module Middleman::Sitemap
|
|||
# Simple aliases
|
||||
delegate :path, :source_file, :store, :app, :ext, :to => :page
|
||||
|
||||
# Clear internal frontmatter cache for file if it changes
|
||||
# @return [void]
|
||||
def touch
|
||||
app.cache.remove(:metadata, source_file)
|
||||
end
|
||||
|
||||
# Clear internal frontmatter cache for file if it is deleted
|
||||
# @return [void]
|
||||
def delete
|
||||
app.cache.remove(:metadata, source_file)
|
||||
end
|
||||
|
||||
# Get the metadata for both the current source_file and the current path
|
||||
# @return [Hash]
|
||||
def metadata
|
||||
metadata = app.cache.fetch(:metadata, source_file) do
|
||||
metadata = @page.cache.fetch(:metadata) do
|
||||
data = { :options => {}, :locals => {}, :page => {}, :blocks => [] }
|
||||
|
||||
app.provides_metadata.each do |callback, matcher|
|
||||
|
@ -104,4 +92,4 @@ module Middleman::Sitemap
|
|||
result
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ module Middleman::Extensions
|
|||
app.after_configuration do
|
||||
sitemap.reroute do |destination, page|
|
||||
if exts.include? page.ext
|
||||
app.cache.fetch(:asset_hash, page.path) do
|
||||
page.cache.fetch(:asset_hash) do
|
||||
digest = Digest::SHA1.file(page.source_file).hexdigest[0..7]
|
||||
destination.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue