Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@cy6erGn0m cy6erGn0m commented Feb 5, 2016

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment