Caching Setup
Configure caching for optimal performance
Overview
Configure caching for optimal performance
This guide explains how to set up and optimize caching for the Mindware Blog project to achieve faster builds and better CI/CD performance.
🚀 Quick Start
1. Local Development Caching
The project is already configured with Turbo caching. Simply run:
# Build with local caching
pnpm turbo build --filter=@mindware-blog/site
# Or build all packages
pnpm turbo build
2. Remote Caching Setup (Recommended)
For the best performance, especially in CI/CD, set up remote caching:
Option A: Vercel Remote Cache (Recommended)
-
Install Turbo CLI globally:
npm install -g turbo -
Login to Vercel:
npx turbo login -
Link your project:
npx turbo link -
Add secrets to GitHub repository:
- Go to your repository settings
- Navigate to "Secrets and variables" → "Actions"
- Add these secrets:
TURBO_TOKEN: Your Turbo token (fromnpx turbo login)TURBO_TEAM: Your Vercel team ID (optional)
Option B: Self-Hosted Remote Cache
- Set up a remote cache server (using Redis, S3, or similar)
- Configure environment variables:
export TURBO_REMOTE_CACHE_URL="your-cache-url" export TURBO_REMOTE_CACHE_TOKEN="your-token"
📊 Cache Configuration
Enhanced turbo.json
The project now includes optimized caching configuration:
- Global Dependencies: Files that affect all tasks
- Task-Specific Inputs: Only relevant files for each task
- Output Caching: Build artifacts are cached and reused
GitHub Actions Caching
The workflow now includes multiple cache layers:
- pnpm Cache: Dependencies and package store
- Turbo Cache: Build outputs and task results
- Node Modules Cache: Installed packages
- Build Artifacts Cache: Compiled outputs
🔧 Cache Verification
Local Cache Status
# Check cache status
pnpm turbo build --filter=@mindware-blog/site --dry-run
# Clear cache if needed
pnpm turbo build --filter=@mindware-blog/site --force
CI/CD Cache Monitoring
The workflow now includes cache statistics in the build logs:
- Turbo cache size
- pnpm cache size
- Node modules size
- Build output sizes
🎯 Performance Optimizations
1. Input Patterns
The enhanced turbo.json includes specific input patterns for each task:
- Build: Only watches source files, assets, and configuration
- Lint: Only watches source files and ESLint config
- Test: Only watches test files and test configuration
- TypeCheck: Only watches TypeScript files and config
2. Cache Invalidation
Caches are invalidated when:
- Source files change (for build tasks)
- Configuration files change (global dependencies)
- Lock files change (for dependency caches)
3. Parallel Execution
Tasks run in parallel when possible:
- Lint and typecheck can run simultaneously
- Tests can run in parallel with visual regression
- Build tasks respect dependencies but cache results
🚨 Troubleshooting
Cache Not Working
-
Check cache configuration:
pnpm turbo build --filter=@mindware-blog/site --dry-run -
Clear and rebuild:
pnpm turbo build --filter=@mindware-blog/site --force -
Verify file patterns in turbo.json
Remote Cache Issues
-
Check authentication:
npx turbo login -
Verify team access:
npx turbo link -
Check environment variables in CI
Performance Issues
- Monitor cache hit rates in CI logs
- Check cache sizes in build statistics
- Verify input patterns are not too broad
📈 Expected Performance Gains
With proper caching setup:
- First build: Normal speed
- Subsequent builds: 50-80% faster
- CI/CD builds: 60-90% faster with remote cache
- Dependency installation: 70-90% faster with pnpm cache
🔄 Cache Maintenance
Regular Maintenance
-
Clear old caches periodically:
pnpm turbo build --filter=@mindware-blog/site --force -
Update cache keys when configuration changes significantly
-
Monitor cache sizes to avoid storage issues
CI/CD Cache Management
- Caches are automatically managed by GitHub Actions
- Old caches are automatically cleaned up
- Cache keys include file hashes for automatic invalidation
📚 Additional Resources
🆘 Support
If you encounter issues with caching:
- Check the build logs for cache statistics
- Verify your turbo.json configuration
- Ensure all required secrets are set in GitHub
- Check the troubleshooting section above
For additional help, refer to the project documentation or create an issue in the repository.