Skip to content

Commit

Permalink
Update docs for OHC
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki Ishikawa committed May 1, 2018
1 parent 720f7fd commit 375afc9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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

Expand Down
40 changes: 39 additions & 1 deletion modules/doc/src/main/tut/docs/cache-implementations.md
Expand Up @@ -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)
}
```
1 change: 1 addition & 0 deletions modules/doc/src/main/tut/index.md
Expand Up @@ -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

Expand Down

0 comments on commit 375afc9

Please sign in to comment.