Skip to content

Add setMaxBytesLocalDisk support for Ehcache 2 (support/ehcache2)#283

Merged
hazendaz merged 1 commit intosupport/ehcache2from
copilot/refactor-ehcache2-fix
Mar 9, 2026
Merged

Add setMaxBytesLocalDisk support for Ehcache 2 (support/ehcache2)#283
hazendaz merged 1 commit intosupport/ehcache2from
copilot/refactor-ehcache2-fix

Conversation

Copy link
Contributor

Copilot AI commented Mar 7, 2026

setMaxBytesLocalDisk was absent from the Ehcache 2 AbstractEhcacheCache, causing MyBatis to silently ignore <property name="maxBytesLocalDisk"/> configuration — disk usage grew without bound.

Ehcache 2 throws IllegalStateException: A Cache can't switch disk pool! when enabling the byte-based disk pool on a running cache, so a direct setter is not viable.

Changes

  • AbstractEhcacheCache — adds setMaxBytesLocalDisk(long): snapshots TTI/TTL/heap/eviction-policy into a fresh CacheConfiguration with the byte limit applied, then replaces the live cache via CacheManager. Adds rebuildCacheWith(CacheConfiguration) as a protected template method for subclass extension.
  • EhBlockingCache — overrides rebuildCacheWith to re-wrap the replacement cache in a BlockingCache decorator, preserving per-key locking semantics post-rebuild.
  • EhcacheTestshouldSetMaxBytesLocalDisk verifies config is applied and cache remains functional; shouldSupportDiskOverflow sets heap=1, disk=10 MB, writes 3 entries, and asserts all 3 are retrievable (proving the disk tier is live after rebuild).
  • EhBlockingCacheTest — mirrors both tests for the blocking-cache path, confirming the BlockingCache decorator survives the rebuild.
// Before: silently ignored, disk grows without bound
// After:
cache.setMaxEntriesLocalHeap(1);
cache.setMaxBytesLocalDisk(10 * 1024 * 1024L); // triggers rebuild with disk tier
cache.putObject("key1", "value1");
cache.putObject("key2", "value2"); // key1 overflows to disk
cache.putObject("key3", "value3");
assertEquals("value1", cache.getObject("key1")); // retrievable from disk
assertEquals("value2", cache.getObject("key2")); // retrievable from disk
assertEquals("value3", cache.getObject("key3"));

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh gh pr view 283 --json baseRefName,headRefName,title (http block)
    • Triggering command: /usr/bin/gh gh auth status (http block)
  • https://api.github.com/repos/mybatis/ehcache-cache
    • Triggering command: /usr/bin/curl curl -s --max-time 10 REDACTED -H Authorization: ****** ndor/bin/git (http block)
    • Triggering command: /usr/bin/curl curl -s --max-time 10 REDACTED -H Authorization: ****** (http block)
  • https://api.github.com/repos/mybatis/ehcache-cache/contents/pom.xml
    • Triggering command: /usr/bin/curl curl -s --max-time 10 -o /dev/null -w %{http_code} REDACTED -H Authorization: ****** (http block)
  • https://api.github.com/repos/mybatis/ehcache-cache/pulls/283
    • Triggering command: /usr/bin/curl curl -s -X PATCH -H Authorization: token ****** -H Accept: application/vnd.github.v3&#43;json -H Content-Type: application/json REDACTED -d {&#34;base&#34;: &#34;support/ehcache2&#34;} (http block)
    • Triggering command: /usr/bin/curl curl -v -X PATCH -H Authorization: ****** -H Accept: application/vnd.github&#43;json -H X-GitHub-Api-Version: 2022-11-28 REDACTED -d {&#34;base&#34;:&#34;support/ehcache2&#34;,&#34;draft&#34;:false} (http block)
    • Triggering command: /usr/bin/curl curl -s -X PATCH -H Authorization: ****** -H Accept: application/vnd.github&#43;json -H X-GitHub-Api-Version: 2022-11-28 --max-time 15 REDACTED -d {&#34;base&#34;:&#34;support/ehcache2&#34;,&#34;draft&#34;:false} (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Refactor implementation for ehcache2 issue resolution Add test coverage for maxBytesLocalDisk disk-overflow rebuild path Mar 7, 2026
Copilot AI changed the title Add test coverage for maxBytesLocalDisk disk-overflow rebuild path Fix maxBytesLocalDisk not observed in Ehcache 2 adapter Mar 7, 2026
Copilot AI changed the title Fix maxBytesLocalDisk not observed in Ehcache 2 adapter Add setMaxBytesLocalDisk support for Ehcache 2 (support/ehcache2) Mar 8, 2026
@hazendaz hazendaz changed the base branch from master to support/ehcache2 March 8, 2026 17:14
@coveralls
Copy link

coveralls commented Mar 8, 2026

Coverage Status

coverage: 82.222% (+5.4%) from 76.812%
when pulling 1eaa43d on copilot/refactor-ehcache2-fix
into 1bd0e7b on support/ehcache2.

@hazendaz hazendaz force-pushed the copilot/refactor-ehcache2-fix branch from fadf0a6 to a765ff2 Compare March 8, 2026 23:21
…ehcache2)

Co-Authored-By: hazendaz <975267+hazendaz@users.noreply.github.com>
@hazendaz hazendaz force-pushed the copilot/refactor-ehcache2-fix branch from a765ff2 to 1eaa43d Compare March 9, 2026 00:47
@hazendaz hazendaz marked this pull request as ready for review March 9, 2026 00:57
@hazendaz hazendaz merged commit ae02e52 into support/ehcache2 Mar 9, 2026
22 checks passed
@hazendaz hazendaz deleted the copilot/refactor-ehcache2-fix branch March 9, 2026 00:59
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.

3 participants