Last active
August 29, 2015 14:01
-
-
Save lazyval/0b6613492a9f7de9f8ef to your computer and use it in GitHub Desktop.
uaagent compilation issues
This file contains hidden or 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
# 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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
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() | |
} | |
} |
This file contains hidden or 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
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