I just built a class that will read a .properties file and get values from it. Since I'll be making frequent calls to this for configuration values throughout my app, how can I cache access to this file so I'm not reading the entire file on every call?
Would I need to do this?
Here's the class:
I created another class which extends Property (above):
In my app I'd then make calls to those methods when needed. Won't I be adding some real overhead by constantly calling & reading this file?
Advice is much appreciated, thanks!
Joined: Sep 16, 2005
Why not just define your class as a Singleton?
There is no emoticon for what I am feeling!
Joined: Jun 19, 2001
dont use absolute file paths. use relative file paths or even better load the properties as a resource from classpath.
if you need frequent access to these properties then just keep a reference to it and pass it to the dependent objects.
Joined: Jan 29, 2003
I wrote a properties cache for my first Java project. It has a map keyed on filename and each entry in the map is a collection of properties. It reads all the properties files in a list of directories into cache in a single call. For server apps I always have a management API that lets me clear and reload one or all files in the cache. It looks something like ...
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Oct 30, 2001
This is a good opportunity to use SoftReference. If you store your cache of Properties in a SoftReference, then Java will delete your cache automatically, in a low-memory situation. That's fine, because the cache contents can be recreated from the Properties files at any time. By using SoftReference, you can stop worrying about whether your cache is getting too big.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P