Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommend practices for storing application transient config

I am writing a small personal file-server with Play! and it's my first web application. What are the recommended practices for storing preferences that users can modify through a preference panel.

My first idea was to use a property file in the conf directory, but I must be able to modify it during runtime. Is the conf directory writable, whatever the deployment option ?

Are there built-in options for that or is there a better approach ?

like image 718
paradigmatic Avatar asked Oct 10 '22 13:10

paradigmatic


1 Answers

As said by Kim Stebel, the usual solution is to use what you application already has, which is most of the time a database engine, being relational or not. That's because most of the time, user preferences come after some other data where already persisted.

But in your case, it seems that the file system is you persistence engine, and you don't seems to need transactions or excessively good read/write performance for the discussed feature, so I would keep that part the simplest possible until some other persistence engine is needed: I would just serialize user preference object to some text format (JSON or XML comes to mind) and save them in the filesystem: no mapping hell for now, no premature choice (and even the possibility to corrupt^W edit your user preference with your favorite text editor, directly on the server, yeah ;)

That being said, there is a ton of good framework for that job, in Scala or from the Java ecosystem.

For the XML mapping, I don't thing Scala native library is the best choice. It's easy to produce XML structure with it, but the mapping from XML to Scala object is at best horrible. XStream (http://x-stream.github.io/) is quite good for that, but you will have to use Java collection, or add your own (and that wasn't my idea of the 'most simple').

For JSON mapping, there is several really good libraries in Scala. Google and other stackoverflowers may have more details, but I know there is at least these two:

  • Lift-JSON (https://github.com/lift/lift/tree/master/framework/lift-base/lift-json/) - I used that one, and even if the API seems sometimes strange to me and the doc is a little too light, the automatic deserialization to case class is really cool;
  • Jerkson (https://github.com/codahale/jerkson) is reported to be quite simple and good

Hope it helps,

like image 173
fanf42 Avatar answered Oct 13 '22 10:10

fanf42