Skip to content

Instantly share code, notes, and snippets.

@cy6erGn0m
Created February 5, 2016 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cy6erGn0m/b2d3477d2e053a41e51a to your computer and use it in GitHub Desktop.
Save cy6erGn0m/b2d3477d2e053a41e51a to your computer and use it in GitHub Desktop.
Kotlin ehcache example
val cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.with(CacheManagerPersistenceConfiguration(storagePath))
.withCache("kweetsCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder<Int, Kweet>()
.withResourcePools(ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(1000, EntryUnit.ENTRIES)
.offheap(10, MemoryUnit.MB)
.disk(100, MemoryUnit.MB, true)
)
.buildConfig(Int::class.javaObjectType, Kweet::class.java))
.build(true)
@cy6erGn0m
Copy link
Author

Notice Int::class.javaObjectType that is required for ehcache to avoid the following

Caused by: java.lang.IllegalStateException: Cache 'kweetsCache' creation in EhcacheManager failed.
    at org.ehcache.EhcacheManager.createCache(EhcacheManager.java:226)
    at org.ehcache.EhcacheManager.init(EhcacheManager.java:464)
    ... 17 more
Caused by: java.lang.RuntimeException: org.ehcache.spi.serialization.UnsupportedTypeException: No serializer found for type 'int'
    at org.ehcache.EhcacheManager.createNewEhcache(EhcacheManager.java:305)
    at org.ehcache.EhcacheManager.createCache(EhcacheManager.java:202)
    ... 18 more
Caused by: org.ehcache.spi.serialization.UnsupportedTypeException: No serializer found for type 'int'
    at org.ehcache.spi.serialization.DefaultSerializationProvider$AbstractProvider.getClassFor(DefaultSerializationProvider.java:244)
    at org.ehcache.spi.serialization.DefaultSerializationProvider$PersistentProvider.createSerializer(DefaultSerializationProvider.java:165)
    at org.ehcache.spi.serialization.DefaultSerializationProvider$AbstractProvider.createKeySerializer(DefaultSerializationProvider.java:202)
    at org.ehcache.spi.serialization.DefaultSerializationProvider.createKeySerializer(DefaultSerializationProvider.java:77)
    at org.ehcache.EhcacheManager.createNewEhcache(EhcacheManager.java:295)
    ... 19 more

@vick-ram
Copy link

vick-ram commented May 2, 2024

Not necessarily Int::class.javaObjectType but your Entity's primary key.

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