gnodet opened a new pull request, #13522:
URL: https://github.com/apache/maven/pull/13522

   ## Summary
   
   Extracts `PluginRealmCache.invalidate(Artifact)` from #13094 into a 
standalone draft PR for design discussion before merge.
   
   This PR adds a `default invalidate(org.apache.maven.api.Artifact)` method to 
`PluginRealmCache` so IDE integrators (m2e, IntelliJ, etc.) and Maven Daemon 
can purge stale plugin realms when a workspace artifact is rebuilt, without 
restarting the JVM.
   
   `DefaultPluginRealmCache` implements `invalidate()` by:
   - Scanning entries whose resolved artifacts match on 
`groupId:artifactId:version`
   - Disposing the `ClassRealm` via `ClassWorld.disposeRealm()` for each 
matched entry
   - Removing the entry from the cache map
   
   The default is a **no-op**, preserving backward compatibility for all 
existing cache implementations.
   
   ## Why a separate PR?
   
   This is deliberately a **draft** pending design discussion in MNG-8767. 
Concerns:
   
   ### 1. Scope: all 5 caches, not just one
   
   The invalidation pattern should be generalized across all Maven caches:
   - `PluginRealmCache` (this PR)
   - `ExtensionRealmCache`
   - `ProjectRealmCache`
   - `PluginArtifactsCache`
   - `MavenMetadataCache`
   
   ### 2. Design options
   
   **Option A — Per-cache `invalidate(Artifact)`** (current PR)
   Add `invalidate(Artifact)` to each cache interface independently. Simple, 
incremental, but requires 5 separate changes and callers must know which caches 
to invalidate.
   
   **Option B — Unified `CacheManager` service**
   A single `CacheManager.invalidate(Artifact)` that cascades across all 
caches. Cleaner API for embedders (one call instead of five), but adds an 
abstraction layer.
   
   **Option C — Session-scoped caches**
   Make caches session-scoped instead of singleton. Each project refresh gets 
fresh caches — no invalidation API needed. Changes cache lifecycle semantics 
and may affect performance for daemon scenarios.
   
   ### 3. mvnd implications
   
   Maven Daemon keeps a long-lived JVM across builds, making cache staleness a 
first-class concern — the same problem as m2e but in a different context. The 
design should account for:
   - mvnd's existing `BuildCacheManager` / cache purging logic
   - Whether mvnd could use the same SPI instead of maintaining its own cache 
management
   - Option C (session-scoped caches) is particularly relevant to mvnd, which 
already manages cache lifecycle per-build
   
   ### 4. Invalidation granularity
   
   Should `invalidate()` take an `Artifact`, a `Plugin`, a `Project`, or 
provide a `flush()` that resets everything? m2e uses project-scoped flushing; 
mvnd may need artifact-level or full flush.
   
   ## Related
   
   - Implements: MNG-8767
   - Extracted from: #13094
   - WorkspaceReader SPI (the paired PR): #13094
   
   _Hermes Agent (Claude Sonnet 4.5) on behalf of Guillaume Nodet_
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to