{title:'Config Stores', updated:'9.0.0'}

Configuration files are stored in entities called Stores.

The methods that need to be implemented on a store are:

- {@link oaj.config.store.ConfigStore}
  - {@link oaj.config.store.ConfigStore#read(String) read(String)}
  - {@link oaj.config.store.ConfigStore#write(String,String,String) write(String,String,String)}
  - {@link oaj.config.store.ConfigStore#update(String,String) update(String,String)}

Read is self-explanatory:

| public String read(String name) { | // Return the contents of the specified configuration. | }

Write is slightly trickier:

| public String write(String name, String oldContents, String newContents) { | | // If the old contents match the current stored contents, the new contents will get stored, | // and the method returns null indicating success. | | // If the old contents DO NOT match the current stored contents (i.e. it was modified in some way), | // the new contents are NOT stored, and the method returns the current stored contents. | | // If the old contents are null, then just always write the new contents. | }

The update method is called whenever the stored file gets modified externally:

| public String update(String name, String newContents) { | // Do something with the updated contents. | }

Two configuration stores are provided by default:

- {@link oaj.config.store.FileStore} - File-system storage.
- {@link oaj.config.store.MemoryStore} - In-memory storage.

The store is defined on the Config object via the following setting:

- {@link oaj.config.Config.Builder}
  - {@link oaj.config.Config.Builder#store(ConfigStore) store(ConfigStore)}

##### Example:

| // Create a config with in-memory storage. | Config config = Config. create("MyConfig.cfg").store(ConfigMemoryStore. DEFAULT).build();

The default store used is {@link oaj.config.store.FileStore#DEFAULT} which defines the execution directory as the file system directory to store and retrieve files.