Skip to content

Instantly share code, notes, and snippets.

@lazyval
Last active August 29, 2015 14:01
Show Gist options
  • Save lazyval/0b6613492a9f7de9f8ef to your computer and use it in GitHub Desktop.
Save lazyval/0b6613492a9f7de9f8ef to your computer and use it in GitHub Desktop.
uaagent compilation issues
# SBT
boot/
lib_managed/
target/
.history
# Eclipse
.cache
.classpath
.project
.scala_dependencies
.settings
.target/
# IntelliJ
.idea/
*.iml
*.ipr
*.iws
out/
# TextMate
*.tmproj
# Mac
.DS_Store
organization := "com.github.lazyval"
name := "uadetector"
// version is defined in version.sbt in order to support sbt-release
scalaVersion := "2.10.4"
scalacOptions ++= Seq("-unchecked", "-deprecation", "-Xlint")
libraryDependencies ++= Seq(
"net.sf.uadetector" % "uadetector-core" % "0.9.16",
"net.sf.uadetector" % "uadetector-resources" % "2013.04",
"com.google.guava" % "guava" % "15.0"
)
initialCommands in console := "import com.github.lazyval._"
scalaSource in Compile := baseDirectory.value
scalaSource in Test := baseDirectory.value
javaSource in Compile := baseDirectory.value
javaSource in Test := baseDirectory.value
resourceDirectory in Compile := baseDirectory.value
resourceDirectory in Test := baseDirectory.value
import net.sf.uadetector.service._
import net.sf.uadetector._
import com.google.common.cache.CacheBuilder
import com.google.common.cache.Cache
import java.util.concurrent.TimeUnit
object CachedUserAgentStringParser extends UserAgentStringParser {
private val parser = UADetectorServiceFactory.getCachingAndUpdatingParser
private val cache: Cache[String, ReadableUserAgent] = CacheBuilder
.newBuilder()
.maximumSize(100)
.expireAfterWrite(2, TimeUnit.HOURS)
.build()
override def getDataVersion(): String = parser.getDataVersion
override def parse(userAgentString: String): ReadableUserAgent = {
var result = cache.getIfPresent(userAgentString)
if (result == null) {
result = parser.parse(userAgentString)
cache.put(userAgentString, result)
}
result
}
override def shutdown() {
parser.shutdown()
}
}
version in ThisBuild := "0.1.0-SNAPSHOT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment