diff --git a/README.md b/README.md index 190a7826..a9b6c5dc 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ The following cache implementations are supported, and it's easy to plugin your * Redis * [Caffeine](https://github.com/ben-manes/caffeine) * [cache2k](https://github.com/cache2k/cache2k) +* [OHC](https://github.com/snazy/ohc) ## Documentation diff --git a/modules/doc/src/main/tut/docs/cache-implementations.md b/modules/doc/src/main/tut/docs/cache-implementations.md index 53cb4b06..4d9d971e 100644 --- a/modules/doc/src/main/tut/docs/cache-implementations.md +++ b/modules/doc/src/main/tut/docs/cache-implementations.md @@ -181,8 +181,46 @@ val underlyingCache2kCache = new Cache2kBuilder[String, String]() {}.expireAfter implicit val customisedCache2kCache: Cache[String] = Cache2kCache(underlyingCache2kCache) ``` +### OHC + +SBT: + +``` +libraryDependencies += "com.github.cb372" %% "scalacache-ohc" % "0.24.0" +``` + +Usage: + +```tut:silent +import scalacache._ +import scalacache.ohc._ +import org.caffinitas.ohc.CacheSerializer + +implicit val valueSerializer: CacheSerializer[String] = OhcCache.stringSerializer +implicit val ohcCache: Cache[String] = OhcCache[String] +``` + +This will build a OHC cache with almost default settings. If you want to customize your OHC cache, then build it yourself and pass it to `OhcCache` like this: + +```tut:silent +import scalacache._ +import scalacache.ohc._ +import org.caffinitas.ohc.OHCacheBuilder + +// You have to configure the cache with OHCacheBuilder.timeouts(true) +// if you want to set expiry on individual values. +val underlyingOhcCache = + OHCacheBuilder + .newBuilder() + .keySerializer(OhcCache.stringSerializer) + .valueSerializer(OhcCache.stringSerializer) + .timeouts(true) + .build() +implicit val customisedOhcCache: Cache[String] = OhcCache(underlyingOhcCache) +``` + ```tut:invisible -for (cache <- List(ehcacheCache, redisCache, customisedRedisCache, memcachedCache, customisedMemcachedCache, underlyingCache2kCache)) { +for (cache <- List(ehcacheCache, redisCache, customisedRedisCache, memcachedCache, customisedMemcachedCache, underlyingCache2kCache, ohcCache, customisedOhcCache)) { cache.close()(scalacache.modes.sync.mode) } ``` diff --git a/modules/doc/src/main/tut/index.md b/modules/doc/src/main/tut/index.md index d79430dc..cf2494e0 100644 --- a/modules/doc/src/main/tut/index.md +++ b/modules/doc/src/main/tut/index.md @@ -18,6 +18,7 @@ The following cache implementations are supported, and it's easy to plugin your * Redis * [Caffeine](https://github.com/ben-manes/caffeine) * [cache2k](https://github.com/cache2k/cache2k) +* [OHC](https://github.com/snazy/ohc) ## Compatibility