turboFei commented on PR #7220:
URL: https://github.com/apache/kyuubi/pull/7220#issuecomment-3359323799

   In **Guava’s `Cache` API**, the method `cache.cleanUp()` is used to 
**synchronously perform maintenance operations** on the cache.
   
   Here’s what it does in detail:
   
   ---
   
   ### 🔹 Purpose of `cleanUp()`
   
   * Guava caches perform most maintenance operations (like evicting expired 
entries or removing entries exceeding maximum size) **lazily** — that is, 
during normal cache operations such as `get`, `put`, or `getIfPresent`.
   * The `cleanUp()` method forces the cache to immediately run these pending 
maintenance tasks.
   
   ---
   
   ### 🔹 When to Use It
   
   * Normally, you **don’t need to call** `cleanUp()` yourself; Guava handles 
it during cache operations.
   * But in some cases — like when you want to:
   
     * **Benchmark** cache performance without pending work affecting results.
     * **Manually trigger eviction** (e.g., after setting `expireAfterWrite` or 
`maximumSize`).
     * **Ensure consistency** before shutting down an application or running a 
test — you might explicitly call `cleanUp()`.
   
   ---
   
   ### 🔹 Important Notes
   
   * `cleanUp()` does **not** block future writes or reads. It just runs 
pending maintenance at the time of the call.
   * If your cache uses expiration or size-based eviction, `cleanUp()` ensures 
those rules are applied **immediately**, rather than waiting for the next 
normal operation.
   * It’s typically lightweight but should not be called in a tight loop — 
Guava already optimizes cleanup frequency internally.
   
   ---
   
   ✅ **In short**:
   `cache.cleanUp()` forces the cache to process pending evictions (expired 
entries, over-capacity entries, etc.) right away instead of waiting for normal 
access patterns to trigger cleanup.
   
   ---
   
   Would you like me to also show you a **small code example** demonstrating 
how entries are only removed after `cleanUp()` is called?
   


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to