How to use Memcached with the Scala Play Framework 2.2? - scala

I want to apply memcached on my Scala project, but i don't know how to apply it. My project takes too much time to retrieve the whole set of results from database.
If anyone knows then please tell me the steps to apply it.

First look at using a local cache: http://www.playframework.com/documentation/2.2.x/ScalaCache
It uses EHCache by default but you can replace the cache plugin with one that wraps a memcached client, if you think it is necessary.
Example of how to write a cache plugin: https://github.com/mumoshu/play2-memcached
An example memcached client: https://github.com/Atry/memcontinuationed

Related

how to disclude development.conf from docker image creation of play framework application artifact

Using scala playframework 2.5,
I build the app into a jar using sbt plugin PlayScala,
And then build and pushes a docker image out of it using sbt plugin DockerPlugin
Residing in the source code repository conf/development.conf (same where application.conf is).
The last line in application.conf says include development which means that in case development.conf exists, the entries inside of it will override some of the entries in application.conf in such way that provides all default values necessary for making the application runnable locally right out of the box after the source was cloned from source control with zero extra configuration. This technique allows every new developer to slip right in a working application without wasting time on configuration.
The only missing piece to make that architectural design complete is finding a way to exclude development.conf from the final runtime of the app - otherwise this overrides leak into production runtime and obviously the application fails to run.
That can be achieved in various different ways.
One way could be to some how inject logic into the build task (provided as part of the sbt pluging PlayScala I assume) to exclude the file from the jar artifact.
Other way could be injecting logic into the docker image creation process. this logic could manually delete development.conf from the existing jar prior to executing it (assuming that's possible)
If you ever implemented one of the ideas offered,
or maybe some different architectural approach that gives the same "works out of the box" feature, please be kind enough to share :)
I usually have the inverse logic:
I use the application.conf file (that Play uses by default) with all the things needed to run locally. I then have a production.conf file that starts by including the application.conf, and then overrides the necessary stuff.
for deploying to production (or staging) I specify the production/staging.conf file to be used
This is how I solved it eventually.
conf/application.conf is production ready configuration, it contains placeholders for environment variables whom values will be injected in runtime by k8s given the service's deployment.yaml file.
right next to it, conf/development.conf - its first line is include application.conf and the rest of it are overrides which will make the application run out of the box right after git clone by a simple sbt run
What makes the above work, is the addition of the following to build.sbt :
PlayKeys.devSettings := Seq(
"config.resource" -> "development.conf"
)
Works like a charm :)
This can be done via the mappings config key of sbt-native-packager:
mappings in Universal ~= (_.filterNot(_._1.name == "development.conf"))
See here.

sails.getDatastore is not a function

I'm currently in the middle of upgrading our API from v0.12 of Sails to v1. Not the easiest task, but will be worth it.
The current problem I'm having, is converting our old "ModelName.query" calls to the new style, which is supposedly "sails.getDatastore". Great, fine.
Except, that when trying to do this in config/bootstrap.js, I constantly get the error "sails.getDatastore is not a function".
Yes, I am using the default sails-hook-orm, the .sailsrc has it turned on explicitly; and yes, I have globals turned on.
Is the problem that the function isn't registered until after bootstrap? Because that is not an option for us; bootstrap is validating our database schema before lift (custom code, using native queries), so our production servers fail to deploy if we missed a database update. It eliminates a ton of human error.
Thanks for taking the 1.0 plunge!
I'm not sure what you mean by the "default" sails-hook-orm -- that hook is installed directly as a dependency on each Sails 1.0 project -- but I can almost guarantee that the version you're using is not correct. I would do:
npm cache clean
npm install sails-hook-orm#beta
in your project to make sure you get the latest (currently v2.0.0-21). It adds getDatastore to the app object when it initializes.

Unable to import play.api.db.databases

I am developing an application in Scala Play 2.5.4. I want to test my database interactions, and am attempting to do so by the method recommended in this page.
The trouble is, I am unable to import the object play.api.db.Databases. I suspect that I may need to add something to my build.sbt file, but since this is part of the Play API, I'm not so sure that this is the case.
There are some things available, but not what is shown in the API doc
Yes, you need to add in your build.sbt file this:
libraryDependencies += jdbc
After that, reload activator and update your dependencies (activator update/sbt update).
Note that after this you will need also to add the jdbc driver of the database you intend to use. See more info in https://www.playframework.com/documentation/2.5.x/ScalaDatabase
Edit
As stated in the comments, this may cause problems with Slick.
Unfortunately the classes you need to use are provided by that module, so if this causes you problems, you can try two things:
Extract the class/methods you need and put them in your project: you can get the Databases class code in https://github.com/playframework/playframework/blob/2.5.x/framework/src/play-jdbc/src/main/scala/play/api/db/Databases.scala
Try to disable the DBModule. I'm not quite sure about the syntax, so try each one of those:
play.modules.enabled -= "play.api.db.DBModule"
play.modules.disabled += "play.api.db.DBModule"
For people who do not have dependency to Slick but have the same problem. If you have added dependencies to jdbc and your DB driver (for example Postgresql) and problem still exists, reindexing of all dependencies via sbt is required. In my case closing IntelliJ Idea and subsequent reopening project back causes dependencies reindexing and problem was gone.

How to change configuration in play dynamically via JMX

I have my configuration for my Scala Play application in my application.conf file.
For now, everytime I want to change the configuration I have to make a deployment.
Can anybody help me finding out, how to expose the Configuration as a MBean?
I would like to change the configuration without deployment.
Didn't find any documentation on this.
Redeploy just for a configuration change is really boring and I understand you want to avoid that.
Changing configuration while the application is running is a risky operation and I would not recommend going in that direction.
But there are a few techniques that the framework provides that would only require a restart of the application.
Play allows you to point to an external file with your configuration
$ your-app -Dconfig.file=/full/path/to/conf/application-prod.conf
Besides that in your conf file you can use environment variables, so you can configure different servers differently using the same application.conf
my.key = defaultvalue
my.key = ${?MY_KEY_ENV}
And run your app using
$ your-app -DMY_KEY_ENV=bar
Reference:
https://www.playframework.com/documentation/2.4.x/Production
https://www.playframework.com/documentation/2.4.x/ProductionConfiguration

FLV MetaData Injection

I was wondering if there was a sever side system for injecting metaData into FLVs recorded using a streaming server like Red5. I don't want to hack in a command line injector, I would like to use a .Net, CF or Java solution.
Caveat: I know that Red5 has its own Metadata.xml, I want to inject metaData directly into the FLV.
I can recommend you to use flvedit by Marc-André Lafortune! Its written in Ruby and works awesome!
Indeed its a command-line-tool but the only thing you have to do is something like:
"flvedit myawesomefile.flv --update --save thenameoftheflvfilewithmetadata.flv"
;)
Here is the link:
http://github.com/marcandre/flvedit/tree/master
I need make my server side app to inject metadata to flv as well. I found this jflvtool. I wonder if anyone here had used this extensively and has anyfeedback on how mature the project is.