Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 10, 2025

Summary

  • Implements time-based caching for non-specific package versions (currently @latest)
  • Resolves issue Support caching for non specific versions #17 where packages like lodash@latest would trigger npm install repeatedly within minutes
  • Cache has a configurable timeout (default: 5 minutes)
  • Only non-specific versions are cached; exact versions like @4.17.21 are not cached

Implementation Details

  • Added caching functions to both npm and bun resolvers
  • Cache stored in OS temp directory (/tmp/use-m-cache or equivalent)
  • Graceful error handling - cache failures don't break functionality
  • Thread-safe cache operations with proper file locking considerations

Performance Improvements

  • Second call to lodash@latest shows ~3x speed improvement (1160ms → 388ms in demo)
  • Reduces unnecessary network calls and npm registry load
  • Maintains existing behavior for specific versions

Test Coverage

  • Added comprehensive test suite (tests/caching.test.mjs)
  • Tests cache creation, reuse, expiration, and non-caching scenarios
  • Added demonstration script (examples/caching-demo.mjs) showing performance gains
  • All existing tests continue to pass

Future Enhancements

The foundation is in place to extend caching to:

  • Major version ranges like @4, @4.x
  • Semver ranges like ^4.0.0, ~4.0.0
  • Custom cache timeout configuration

🤖 Generated with Claude Code


Resolves #17

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #17
@konard konard self-assigned this Sep 10, 2025
konard and others added 2 commits September 10, 2025 07:57
Implements time-based caching for non-specific versions (currently @latest)
to avoid repeated npm lookups within a configurable time window (default 5 minutes).

Features:
- Caches resolved versions for @latest package requests
- 5-minute cache timeout (configurable)
- Cache stored in OS temp directory
- Graceful fallback on cache errors
- Only caches non-specific versions (exact versions like @4.17.21 are not cached)

This solves issue #17 where packages like lodash@latest would be npm installed
again within minutes instead of using cached results.

Testing:
- Added comprehensive test suite for caching functionality
- Added demonstration script showing cache performance improvements
- All existing tests continue to pass

Future enhancements can extend this to major version ranges like @4, @4.x, etc.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@konard konard changed the title [WIP] Support caching for non specific versions Add caching support for non-specific package versions Sep 10, 2025
@konard konard marked this pull request as ready for review September 10, 2025 05:10
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.

Support caching for non specific versions

2 participants