Skip to content

Improve cache plugin API calls and improve logging#1858

Open
scottrigby wants to merge 1 commit intohelm:mainfrom
scottrigby:fix-netlify-cache-plugin
Open

Improve cache plugin API calls and improve logging#1858
scottrigby wants to merge 1 commit intohelm:mainfrom
scottrigby:fix-netlify-cache-plugin

Conversation

@scottrigby
Copy link
Member

  • Correct cache.restore() and cache.save() to use proper signature (path, { key })
  • Add console.log statements for all cache operations with [CACHE] prefix
  • Accumulate all operation results for combined deploy summary display
  • Log environment variables at start for debugging cache key generation
  • Track restore/save success and errors with clear status indicators

This ensures the plugin follows Netlify's cache-utils API documentation and provides visibility into cache operations during builds.

see:

- Correct cache.restore() and cache.save() to use proper signature (path, { key })
- Add console.log statements for all cache operations with [CACHE] prefix
- Accumulate all operation results for combined deploy summary display
- Log environment variables at start for debugging cache key generation
- Track restore/save success and errors with clear status indicators

This ensures the plugin follows Netlify's cache-utils API documentation and provides visibility into
cache operations during builds.

see:
- https://docs.netlify.com/extend/develop-and-share/develop-build-plugins/#plugin-methods
- https://github.com/netlify/build/blob/main/packages/cache-utils/README.md

Signed-off-by: Scott Rigby <scott@r6by.com>
@scottrigby scottrigby force-pushed the fix-netlify-cache-plugin branch from 2c1b6ce to 3d81ff0 Compare October 31, 2025 16:26
@scottrigby scottrigby marked this pull request as ready for review October 31, 2025 16:27
@scottrigby scottrigby changed the title Fix cache plugin API calls and improve logging Improve cache plugin API calls and improve logging Oct 31, 2025
@scottrigby scottrigby removed this from the Post-Docusaurus site launch milestone Oct 31, 2025
@TerryHowe TerryHowe requested a review from Copilot December 13, 2025 15:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR corrects the Netlify cache plugin API usage and significantly improves logging visibility. The changes align the plugin with Netlify's official cache-utils API documentation by fixing method signatures and add comprehensive console logging with a [CACHE] prefix to track all cache operations during builds.

Key changes:

  • API Corrections: Fixed cache.restore() and cache.save() to use the correct signature (path, { key }) instead of the previous incorrect usage
  • Enhanced Logging: Added console.log statements for all cache operations with clear status indicators (✓, ✗, ⚠, ⊖) and accumulation of results for a combined deploy summary
  • Better Debugging: Added environment variable logging at startup and per-directory processing logs to help debug cache key generation issues

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +103 to +107
console.log('[CACHE] Environment:', {
CACHE_VERSION: process.env.CACHE_VERSION,
CACHE_PER_BRANCH: process.env.CACHE_PER_BRANCH,
NETLIFY_BRANCH: process.env.NETLIFY_BRANCH
});
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The environment object is being logged directly to console.log, which will output "[object Object]" instead of the actual values. To properly display the environment variables, either use JSON.stringify() or log each variable separately.

Suggested change
console.log('[CACHE] Environment:', {
CACHE_VERSION: process.env.CACHE_VERSION,
CACHE_PER_BRANCH: process.env.CACHE_PER_BRANCH,
NETLIFY_BRANCH: process.env.NETLIFY_BRANCH
});
console.log('[CACHE] Environment:', JSON.stringify({
CACHE_VERSION: process.env.CACHE_VERSION,
CACHE_PER_BRANCH: process.env.CACHE_PER_BRANCH,
NETLIFY_BRANCH: process.env.NETLIFY_BRANCH
}, null, 2));

Copilot uses AI. Check for mistakes.

async onPostBuild({ inputs, utils }) {
const results = [];
console.log('[CACHE] ========== Cache Save Starting ==========');
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The onPostBuild function is missing the same environment variable logging that was added to onPreBuild. For consistency and debugging purposes, consider adding similar logging here to help track cache key generation during the save phase. This would help debug issues where save and restore operations might use different keys.

Suggested change
console.log('[CACHE] ========== Cache Save Starting ==========');
console.log('[CACHE] ========== Cache Save Starting ==========');
console.log('[CACHE] Environment:', {
CACHE_VERSION: process.env.CACHE_VERSION,
CACHE_PER_BRANCH: process.env.CACHE_PER_BRANCH,
NETLIFY_BRANCH: process.env.NETLIFY_BRANCH
});

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant