You can choose to limit cache capacity by weight instead of number of entries (cache2k version >1.4.0). This allows for example limiting by (estimated) memory consumption.
This demo also shows cache2ks event listeners and statistics and live adjustments of the cache capacity.
Use mvn spring-boot:run and yarn --cwd limited-exhibit start to start the application, http://localhost:3000 should open automatically
Or check out the Public Demo
