lib/sewing_kit/webpack/manifest.rb in sewing_kit-0.6.1 vs lib/sewing_kit/webpack/manifest.rb in sewing_kit-0.6.2
- old
+ new
@@ -16,17 +16,30 @@
def asset_paths(source)
paths = manifest[source]
paths || {}
end
+ def clear_cache!
+ @manifest = nil
+ @manifest_expiry_time = nil
+ end
+
def manifest
if ::Rails.env.production?
# Cache at class level, as JSON loading/parsing can be expensive.
@manifest ||= load_manifest
else
- # Don't cache outside of production; manifest may change.
- load_manifest
+ # In development, the manifest may change.
+ # A short cache lifetime avoids time consuming node callouts.
+ if self.instance_variable_defined?('@manifest_expiry_time') && @manifest_expiry_time && @manifest_expiry_time >= Time.now
+ @manifest
+ else
+ @manifest = load_manifest
+ @manifest_expiry_time = Time.now + 4
+ end
end
+
+ @manifest
end
private
def manifest_bundled?