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?
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 ...
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.