Skip to content

Commit

Permalink
(puppetlabsGH-121) Use file modification time to invalidate the cache
Browse files Browse the repository at this point in the history
Previously the file cache would use a SHA256 hash of the file content.  While
this works, it's just as easy to use the file modification time stamp. This
reduces the the file IO to check the cache. It's unlikely that a file would have
different content while the modification timestamp stays the same.

Note that this only occurs when the pup4api feature flag is present.
  • Loading branch information
glennsarti committed Apr 10, 2019
1 parent 47e4e90 commit e168f05
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/puppet-languageserver-sidecar/cache/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ def cache_filename(file_key)
end

def calculate_hash(filepath)
Digest::SHA256.hexdigest(read_file(filepath))
if PuppetLanguageServerSidecar.featureflag?('pup4api')
File.mtime(filepath).iso8601
else
Digest::SHA256.hexdigest(read_file(filepath))
end
end
end
end
Expand Down

0 comments on commit e168f05

Please sign in to comment.