Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement cache max age #37

Merged
merged 3 commits into from
Jan 6, 2025
Merged

Implement cache max age #37

merged 3 commits into from
Jan 6, 2025

Conversation

BCsabaEngine
Copy link
Owner

@BCsabaEngine BCsabaEngine commented Jan 6, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new command line option --cachetime for configuring browser caching behavior.
    • Enhanced cache control management in HTTP responses based on the cacheTime parameter.
  • Chores

    • Updated development script with caching parameter.
    • Upgraded development dependencies:
      • Node types
      • TypeScript ESLint plugin and parser
      • Svelte
      • Vite
  • Documentation

    • Added details about the new cachetime option in the README and CHANGELOG.

Copy link

coderabbitai bot commented Jan 6, 2025

Walkthrough

The pull request introduces modifications to the package.json, CHANGELOG.md, README.md, platformio.ini, and several TypeScript files for the svelteesp32 project. Key changes include updating the project version to 1.7.0, modifying the dev:async script to include a cache time parameter, and updating several development dependencies. Additionally, documentation enhancements provide details on the new cache control functionalities and their usage. These changes reflect an overall improvement in caching behavior and project maintenance.

Changes

File Change Summary
package.json - Updated project version to 1.7.0
- Modified dev:async script to include --cachetime=86400 parameter
- Dependency version updates:
@types/node: ^22.10.2^22.10.5
@typescript-eslint/eslint-plugin: ^8.18.2^8.19.1
@typescript-eslint/parser: ^8.18.2^8.19.1
CHANGELOG.md - Added version section ## 1.7
- Added subsection ### 1.7.0 detailing the cachetime command line option
README.md - Introduced "Cache-control" section explaining caching behavior and usage of --cachetime option
- Updated command line options table with --cachetime description
demo/esp32/platformio.ini - Added new board option #board = lolin_s3_mini (commented out)
demo/svelte/package.json - Updated dependency versions:
@typescript-eslint/eslint-plugin: ^8.18.2^8.19.1
@typescript-eslint/parser: ^8.18.2^8.19.1
svelte: ^5.16.0^5.16.2
vite: ^6.0.5^6.0.7
package.script - Added --cachetime=86400 option to command-line invocations for async, psychic, and psychic2 modes
src/commandLine.ts - Added cachetime: number property to ICopyFilesArguments interface
- Updated parse function to include cachetime with default value of 0
src/cppCode.ts - Enhanced getCppCode function to conditionally set cache-control header based on cacheTime parameter

Possibly related PRs

  • feat: etag with cache-control #26: The changes in this PR involve modifications to the src/cppCode.ts file that enhance the handling of cache control headers, which is directly related to the caching behavior updates in the main PR.
  • feat: mime npm package #34: This PR updates the MIME type handling in the src/index.ts file, which is relevant to the overall functionality of the project, including how caching might interact with different content types.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@BCsabaEngine BCsabaEngine marked this pull request as draft January 6, 2025 18:12
@BCsabaEngine BCsabaEngine self-assigned this Jan 6, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
package.json (1)

31-31: LGTM! Consider documenting the cache time parameter.

The addition of a 24-hour cache time is a good default for static assets, especially when combined with ETag validation. This will help improve performance for ESP32-served content.

Consider adding a comment in the README about the new --cachetime parameter and its impact on browser caching behavior.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 006c251 and aad963d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • package.json (2 hunks)
🔇 Additional comments (1)
package.json (1)

57-59: Verify compatibility with the updated dependencies.

The dependency updates look reasonable, with synchronized updates for the TypeScript ESLint packages.

Please verify that the build and tests pass with these updates:

✅ Verification successful

Dependencies are properly synchronized and follow semver guidelines

The package-lock.json is in sync with all three dependency updates, and the TypeScript ESLint packages are correctly updated to the same version. These minor and patch updates should maintain backward compatibility.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the project builds and tests pass with the updated dependencies

# Check if package-lock.json is in sync
if [ -f "package-lock.json" ]; then
  if grep -q "\"@types/node\": \"^22.10.5\"" package-lock.json && \
     grep -q "\"@typescript-eslint/eslint-plugin\": \"^8.19.1\"" package-lock.json && \
     grep -q "\"@typescript-eslint/parser\": \"^8.19.1\"" package-lock.json; then
    echo "package-lock.json is in sync with package.json"
  else
    echo "Warning: package-lock.json might be out of sync with package.json"
  fi
else
  echo "Warning: package-lock.json not found"
fi

# Check for any TypeScript errors in the project
if command -v tsc &> /dev/null; then
  echo "Running TypeScript compiler check..."
  tsc --noEmit
else
  echo "Warning: TypeScript compiler not found in PATH"
fi

Length of output: 454

@BCsabaEngine BCsabaEngine marked this pull request as ready for review January 6, 2025 19:36
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
package.script (1)

1-29: Document the default cache time value.

The script uses a 24-hour (86400 seconds) cache time across all commands. This should be documented to explain the choice of this default value.

Consider adding a comment at the top of the file:

+# Default cache time is set to 24 hours (86400 seconds)
+# This provides a good balance between caching benefits and content freshness

Additionally, consider making the commands DRY-er by extracting common parameters into variables:

#!/bin/bash
CACHE_TIME="--cachetime=86400"
COMMON_ARGS="-s ./demo/svelte/dist ${CACHE_TIME}"
CHANGELOG.md (1)

7-7: Enhance the changelog entry with more details.

While the entry correctly describes the new feature, it could be more helpful with additional details.

Consider expanding the changelog entry:

-- Using the cachetime command line option, you can set whether the browser can cache pages. Together with the ETag switch, you can replace the default no-cache response with a max-age=xy response.
+- Added `--cachetime` command line option to control browser caching behavior:
+  - Default: no-cache (when option is not provided)
+  - Example: `--cachetime=86400` sets Cache-Control: max-age=86400 (24 hours)
+  - Works in conjunction with ETag for optimal caching strategy
README.md (2)

15-16: Fix markdown formatting

Remove the blank line inside the blockquote to comply with markdown best practices.

-> Starting with version v1.7.0, with the cachetime command line option, you can set whether the browser can cache pages
-
🧰 Tools
🪛 Markdownlint (0.37.0)

16-16: null
Blank line inside blockquote

(MD028, no-blanks-blockquote)


181-185: Improve readability with proper punctuation

Add a comma after "By default" to enhance readability.

-By default (when using the ETag), we send no-cache in the cache-control header
+By default, (when using the ETag), we send no-cache in the cache-control header
🧰 Tools
🪛 LanguageTool

[uncategorized] ~182-~182: Did you mean: “By default,”?
Context: ...ESP32_ENABLE_ETAG`. ### Cache-control By default (when using the ETag), we send no-cache...

(BY_DEFAULT_COMMA)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aad963d and 970a4dd.

⛔ Files ignored due to path filters (6)
  • demo/svelte/dist/assets/index-BC9dsMQQ.js is excluded by !**/dist/**
  • demo/svelte/dist/assets/index-DiIOlAIu.js is excluded by !**/dist/**
  • demo/svelte/dist/favicon.png.gz is excluded by !**/dist/**, !**/*.gz
  • demo/svelte/dist/index.html is excluded by !**/dist/**
  • demo/svelte/package-lock.json is excluded by !**/package-lock.json
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • CHANGELOG.md (1 hunks)
  • README.md (3 hunks)
  • demo/esp32/platformio.ini (1 hunks)
  • demo/svelte/package.json (2 hunks)
  • package.json (3 hunks)
  • package.script (1 hunks)
  • src/commandLine.ts (2 hunks)
  • src/cppCode.ts (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • demo/esp32/platformio.ini
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🧰 Additional context used
🪛 Markdownlint (0.37.0)
README.md

16-16: null
Blank line inside blockquote

(MD028, no-blanks-blockquote)

🪛 LanguageTool
README.md

[uncategorized] ~182-~182: Did you mean: “By default,”?
Context: ...ESP32_ENABLE_ETAG`. ### Cache-control By default (when using the ETag), we send no-cache...

(BY_DEFAULT_COMMA)

🔇 Additional comments (4)
demo/svelte/package.json (2)

27-28: LGTM! TypeScript ESLint updates

The updates to @typescript-eslint packages are patch version bumps and should be safe.


43-43: Verify Svelte 5 compatibility with project dependencies

Svelte 5 is currently in beta/alpha stage. Please ensure all project dependencies, especially flowbite-svelte and @sveltejs/vite-plugin-svelte, are compatible with Svelte 5.

Run this script to check for potential compatibility issues:

✅ Verification successful

Dependencies are compatible with Svelte 5.16.2

Both flowbite-svelte and @sveltejs/vite-plugin-svelte explicitly support Svelte 5, making the upgrade to version 5.16.2 safe to proceed with.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check compatibility between Svelte 5 and key dependencies

# Check flowbite-svelte's package.json for Svelte version requirements
curl -s https://registry.npmjs.org/flowbite-svelte/latest | jq -r '.peerDependencies.svelte'

# Check vite-plugin-svelte's package.json for Svelte version requirements
curl -s https://registry.npmjs.org/@sveltejs/vite-plugin-svelte/latest | jq -r '.peerDependencies.svelte'

Length of output: 233

src/cppCode.ts (1)

171-176: LGTM! Cache-control implementation is thorough and consistent.

The cache-control header implementation correctly handles both cases:

  • Sets max-age when cachetime is provided
  • Falls back to no-cache when cachetime is not set

Also applies to: 358-363, 549-554

README.md (1)

241-241: LGTM!

The new --cachetime option is well-documented and follows the existing table format.

"svelte-check": "^4.1.1",
"svelte-preprocess": "^6.0.3",
"tailwindcss": "^3.4.17",
"tslib": "^2.8.1",
"typescript": "^5.7.2",
"vite": "^6.0.5",
"vite": "^6.0.7",
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Update @sveltejs/vite-plugin-svelte to latest version for Vite 6 compatibility

The current version (5.0.3) of @sveltejs/vite-plugin-svelte needs to be upgraded as Vite 6 requires a newer version of this plugin. Other Vite-related dependencies are compatible:

  • vite-plugin-tailwind-purgecss: Already supports Vite 6
  • @sveltejs/vite-plugin-svelte: Needs upgrade to latest version
🔗 Analysis chain

Verify Vite 6 compatibility and migration requirements

Vite 6 is a recent major release. Please ensure you've reviewed the migration guide and addressed any breaking changes.

Run this script to check for potential compatibility issues:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check compatibility between Vite 6 and key dependencies

# Check vite-plugin-svelte's package.json for Vite version requirements
curl -s https://registry.npmjs.org/@sveltejs/vite-plugin-svelte/latest | jq -r '.peerDependencies.vite'

# Check vite-plugin-tailwind-purgecss's package.json for Vite version requirements
curl -s https://registry.npmjs.org/vite-plugin-tailwind-purgecss/latest | jq -r '.peerDependencies.vite'

Length of output: 242


Script:

#!/bin/bash
# Check for any other Vite-related dependencies and their versions
cat demo/svelte/package.json | jq '.dependencies, .devDependencies' | grep -i vite

Length of output: 192

@@ -10,6 +10,7 @@ interface ICopyFilesArguments {
define: string;
gzip: 'true' | 'false' | 'compiler';
etag: 'true' | 'false' | 'compiler';
cachetime: number;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation for the cachetime parameter.

The cachetime parameter should be validated to ensure it's a non-negative value and within reasonable bounds for max-age cache control.

Consider updating the type definition to include validation:

-  cachetime: number;
+  cachetime: {
+    type: (value: number) => number;
+    description: 'max-age cache time in seconds';
+    defaultValue: 0;
+    validate: (value: number) => {
+      if (value < 0) throw new Error('Cache time cannot be negative');
+      if (value > 31536000) throw new Error('Cache time cannot exceed 1 year (31536000 seconds)');
+      return value;
+    }
+  };

Committable suggestion skipped: line range outside the PR's diff.

@BCsabaEngine BCsabaEngine merged commit cbbe0f8 into main Jan 6, 2025
3 checks passed
@BCsabaEngine BCsabaEngine deleted the feat/cache-max-age branch January 6, 2025 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant