-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
131 changed files
with
2,588 additions
and
879 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# Octoparts | ||
# Octoparts [![Build Status](https://travis-ci.org/m3dev/octoparts.svg?branch=develop)](https://travis-ci.org/m3dev/octoparts) [![Coverage Status](https://coveralls.io/repos/m3dev/octoparts/badge.png?branch=develop)](https://coveralls.io/r/m3dev/octoparts?branch=develop) | ||
|
||
[See documentation](http://m3dev.github.io/octoparts/) | ||
|
||
Also see these [Lightning talk slides](https://docs.google.com/presentation/d/1dgbLSaEyWydGX6SaPtGeKXX-6p-0OuUvnWFpiOqgoQo/edit?usp=sharing) from ScalaMatsuri 2014 for a quick explanation of what Octoparts is all about. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.m3.octoparts.cache | ||
|
||
import com.m3.octoparts.cache.key._ | ||
import shade.memcached.Codec | ||
|
||
import scala.concurrent.Future | ||
import scala.concurrent.duration._ | ||
|
||
/** | ||
* A cache whose values are keyed using [[com.m3.octoparts.cache.key.CacheKey]]s. | ||
* | ||
* Usually wraps an instance of a [[RawCache]]. | ||
*/ | ||
trait Cache { | ||
|
||
// TODO shade dependency decoupling | ||
|
||
def get[T](key: CacheKey)(implicit codec: Codec[T]): Future[Option[T]] | ||
|
||
def put[T](key: CacheKey, v: T, ttl: Option[Duration])(implicit codec: Codec[T]): Future[Unit] | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...toparts/cache/client/CacheException.scala → ...m/m3/octoparts/cache/CacheException.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.m3.octoparts.cache.client | ||
package com.m3.octoparts.cache | ||
|
||
import com.m3.octoparts.cache.key.CacheKey | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.m3.octoparts.cache | ||
|
||
import com.m3.octoparts.logging.LogUtil | ||
import play.api.Logger | ||
import shade.memcached.Codec | ||
import skinny.util.LTSV | ||
|
||
import scala.concurrent.duration.Duration | ||
import scala.concurrent.{ ExecutionContext, Future } | ||
|
||
/** | ||
* A decorator to add debug logging to a [[RawCache]] | ||
*/ | ||
class LoggingRawCache(delegate: RawCache)(implicit executionContext: ExecutionContext) extends RawCache with LogUtil { | ||
|
||
def get[T](key: String)(implicit codec: Codec[T]): Future[Option[T]] = { | ||
val f = delegate.get(key)(codec) | ||
f.onSuccess { | ||
case mbVal => Logger.debug(LTSV.dump("Memcached" -> "get", "key" -> key, "is" -> truncateValue(mbVal))) | ||
} | ||
f | ||
} | ||
|
||
def set[T](key: String, value: T, exp: Duration)(implicit codec: Codec[T]): Future[Unit] = { | ||
val f = delegate.set(key, value, exp)(codec) | ||
f.onSuccess { | ||
case done => Logger.debug(LTSV.dump("Memcached" -> "set", "key" -> key, "value" -> truncateValue(value), "duration" -> exp.toString)) | ||
} | ||
f | ||
} | ||
|
||
def close(): Unit = delegate.close() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.m3.octoparts.cache | ||
|
||
import shade.memcached.Codec | ||
|
||
import scala.concurrent.Future | ||
import scala.concurrent.duration.Duration | ||
|
||
/** | ||
* A facade for [[shade.memcached.Memcached]]. | ||
* | ||
* This is called a "raw" cache because it uses raw Strings for keys. | ||
* Usually it will be wrapped by a [[Cache]] implementation for easier access. | ||
* | ||
* Note: We still have a dependency on [[shade.memcached.Codec]], which is not ideal, | ||
* but we can remove it if/when we decide to migrate away from Shade. | ||
*/ | ||
trait RawCache { | ||
|
||
/** | ||
* Fetches a value from the cache store. | ||
* | ||
* @return Some(value) in case the key is available, or None otherwise (doesn't throw exception on key missing) | ||
*/ | ||
def get[T](key: String)(implicit codec: Codec[T]): Future[Option[T]] | ||
|
||
/** | ||
* Sets a (key, value) in the cache store. | ||
* | ||
* The TTL can be Duration.Inf (infinite duration). | ||
*/ | ||
def set[T](key: String, value: T, ttl: Duration)(implicit codec: Codec[T]): Future[Unit] | ||
|
||
/** | ||
* Shutdown and clean up any resources. | ||
*/ | ||
def close(): Unit | ||
|
||
} |
Oops, something went wrong.