Skip to content

Commit

Permalink
fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisjkl committed Nov 7, 2021
1 parent 91706ea commit adfa4dd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
12 changes: 6 additions & 6 deletions modules/docs/src/main/mdoc/docs/cache-implementations.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import scalacache.memcached._
import scalacache.serialization.binary._
import cats.effect.IO

implicit val memcachedCache: Cache[IO, String] = MemcachedCache("localhost:11211")
implicit val memcachedCache: Cache[IO, String, String] = MemcachedCache("localhost:11211")
```

or provide your own Memcached client, like this:
Expand All @@ -36,7 +36,7 @@ val memcachedClient = new MemcachedClient(
new BinaryConnectionFactory(),
AddrUtil.getAddresses("localhost:11211")
)
implicit val customisedMemcachedCache: Cache[IO, String] = MemcachedCache(memcachedClient)
implicit val customisedMemcachedCache: Cache[IO, String, String] = MemcachedCache(memcachedClient)
```

#### Keys
Expand Down Expand Up @@ -65,7 +65,7 @@ import scalacache.redis._
import scalacache.serialization.binary._
import cats.effect.IO

implicit val redisCache: Cache[IO, String] = RedisCache("host1", 6379)
implicit val redisCache: Cache[IO, String, String] = RedisCache("host1", 6379)
```

or provide your own [Jedis](https://github.com/xetorthio/jedis) client, like this:
Expand All @@ -78,7 +78,7 @@ import _root_.redis.clients.jedis._
import cats.effect.IO

val jedisPool = new JedisPool("localhost", 6379)
implicit val customisedRedisCache: Cache[IO, String] = RedisCache(jedisPool)
implicit val customisedRedisCache: Cache[IO, String, String] = RedisCache(jedisPool)
```

ScalaCache also supports [sharded Redis](https://github.com/xetorthio/jedis/wiki/AdvancedUsage#shardedjedis) and [Redis Sentinel](http://redis.io/topics/sentinel). Just create a `ShardedRedisCache` or `SentinelRedisCache` respectively.
Expand All @@ -101,7 +101,7 @@ import cats.effect.unsafe.implicits.global

implicit val clock: Clock[IO] = Clock[IO]

implicit val caffeineCache: Cache[IO, String] = CaffeineCache[IO, String].unsafeRunSync()
implicit val caffeineCache: Cache[IO, String, String] = CaffeineCache[IO, String, String].unsafeRunSync()
```

This will build a Caffeine cache with all the default settings. If you want to customize your Caffeine cache, then build it yourself and pass it to `CaffeineCache` like this:
Expand All @@ -114,7 +114,7 @@ import cats.effect.IO
import cats.effect.unsafe.implicits.global

val underlyingCaffeineCache = Caffeine.newBuilder().maximumSize(10000L).build[String, Entry[String]]
implicit val customisedCaffeineCache: Cache[IO, String] = CaffeineCache(underlyingCaffeineCache)
implicit val customisedCaffeineCache: Cache[IO, String, String] = CaffeineCache(underlyingCaffeineCache)
```

```scala mdoc:invisible
Expand Down
2 changes: 1 addition & 1 deletion modules/docs/src/main/mdoc/docs/flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import cats.effect.unsafe.implicits.global

final case class Cat(id: Int, name: String, colour: String)

implicit val catsCache: Cache[IO, Cat] = MemcachedCache("localhost:11211")
implicit val catsCache: Cache[IO, String, Cat] = MemcachedCache("localhost:11211")

def getCatWithFlags(id: Int)(implicit flags: Flags): Cat = memoize(None) {
// Do DB lookup here...
Expand Down
7 changes: 2 additions & 5 deletions modules/docs/src/main/mdoc/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import scalacache.serialization.binary._

final case class Cat(id: Int, name: String, colour: String)

implicit val catsCache: Cache[IO, Cat] = MemcachedCache("localhost:11211")
implicit val catsCache: Cache[IO, String, Cat] = MemcachedCache("localhost:11211")
```

Note that we made the cache `implicit` so that the ScalaCache API can find it.
Expand All @@ -57,7 +57,7 @@ get("eric")
remove("doraemon")

// Flush the cache
removeAll[Cat]
removeAll[String, Cat]

// Wrap any block with caching: if the key is not present in the cache,
// the block will be executed and the value will be cached and returned
Expand All @@ -73,9 +73,6 @@ cachingF("benjamin")(ttl = None) {
Cat(2, "Benjamin", "ginger")
}
}

// You can also pass multiple parts to be combined into one key
put("foo", 123, "bar")(ericTheCat) // Will be cached with key "foo:123:bar"
```

```scala mdoc:invisible
Expand Down
2 changes: 1 addition & 1 deletion modules/docs/src/main/mdoc/docs/memoization.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import cats.effect.IO

final case class Cat(id: Int, name: String, colour: String)

implicit val catsCache: Cache[IO, Cat] = MemcachedCache("localhost:11211")
implicit val catsCache: Cache[IO, String, Cat] = MemcachedCache("localhost:11211")

def getCat(id: Int): IO[Cat] = memoize(Some(10.seconds)) {
// Retrieve data from a remote API here ...
Expand Down

0 comments on commit adfa4dd

Please sign in to comment.