Skip to content

Replace ConcurrentLRUCache and Cache interface with Caffeine#4516

Open
dsmiley wants to merge 4 commits into
apache:mainfrom
dsmiley:replace-concurrent-lru-cache-with-caffeine-10202347838202579826
Open

Replace ConcurrentLRUCache and Cache interface with Caffeine#4516
dsmiley wants to merge 4 commits into
apache:mainfrom
dsmiley:replace-concurrent-lru-cache-with-caffeine-10202347838202579826

Conversation

@dsmiley

@dsmiley dsmiley commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

I have replaced the custom ConcurrentLRUCache implementation and the org.apache.solr.common.util.Cache interface with Caffeine's Cache in solr-core.

Key changes:

  1. Refactored solr-solrj:
    • Refactored JavaBinCodec.StringCache into an abstract class with getFromCache and putIntoCache methods. This keeps solrj independent of Caffeine.
    • Updated ObjectCache to use ConcurrentHashMap directly and fixed its computeIfAbsent methods to ensure compatibility with existing call-sites (like IndexSchemaFactory).
    • Removed org.apache.solr.common.util.Cache and MapBackedCache.
  2. Updated solr-core:
    • Replaced ConcurrentLRUCache with Caffeine's Cache in IndexSchema and TemplateUpdateProcessorFactory.
    • Deleted org.apache.solr.util.ConcurrentLRUCache.
  3. Updated Tests:
    • Modified TestJavaBinCodec to use a HashMap-based implementation of the now-abstract StringCache.
    • Cleaned up test code that referenced the deleted cache classes.

I verified the changes by ensuring both solrj and core modules compile and by running relevant tests including TestJavaBinCodec, IndexSchemaTest, TemplateUpdateProcessorTest, ObjectCacheTest, and TestJavaBinResponseWriter.


PR created automatically by Jules for task 10202347838202579826 started by @dsmiley


Fork PR: dsmiley#28

google-labs-jules Bot and others added 4 commits June 9, 2026 16:46
This change removes the custom ConcurrentLRUCache implementation and replaces its usages in IndexSchema and TemplateUpdateProcessorFactory with Caffeine's Cache.

Additionally:
- The org.apache.solr.common.util.Cache interface and MapBackedCache have been removed.
- JavaBinCodec.StringCache has been refactored into an abstract class to allow implementers to provide their own caching mechanism without introducing a Caffeine dependency to solr-solrj.
- ObjectCache has been updated to use ConcurrentHashMap directly instead of implementing the removed Cache interface.
- Tests have been updated to use simple Map-based caches where appropriate.

Co-authored-by: dsmiley <377295+dsmiley@users.noreply.github.com>
This change removes the custom ConcurrentLRUCache implementation and replaces its usages in IndexSchema and TemplateUpdateProcessorFactory with Caffeine's Cache.

Additionally:
- The org.apache.solr.common.util.Cache interface and MapBackedCache have been removed.
- JavaBinCodec.StringCache has been refactored into an abstract class to allow implementers to provide their own caching mechanism without introducing a Caffeine dependency to solr-solrj.
- ObjectCache has been updated to use ConcurrentHashMap directly instead of implementing the removed Cache interface.
- Tests have been updated to use simple Map-based caches where appropriate.
- Fixed compilation and spotless check issues from previous attempts.

Co-authored-by: dsmiley <377295+dsmiley@users.noreply.github.com>
- IndexSchema: Added initialCapacity(100) to Caffeine builder to match original ConcurrentLRUCache configuration.
- ObjectCache: Simplified type-safe computeIfAbsent to call the generic one and cast.
- Elaborated on mapping between ConcurrentLRUCache watermarks and Caffeine maximumSize in PR comments.

Co-authored-by: dsmiley <377295+dsmiley@users.noreply.github.com>
- Match original initial sizes in Caffeine builders.
- Add @lucene.internal to StringCache.
- Refactor ObjectCache to be more efficient.
- Ensure all CI issues (compilation, spotless) are resolved.

Co-authored-by: dsmiley <377295+dsmiley@users.noreply.github.com>
@dsmiley

dsmiley commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Changelog or not is debatable. This is an internal change intended to reduce Solr project maintenance by removing things we don't need. I don't imagine a user will be impacted. Even though JavaBinCodec.StringCache is technically public... it's very internal. And users shouldn't assume that all utilities in SolrJ are also for their use as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant