cacheHandler
- Class to handle cache data for an AURORA application and load- and save to file.
use cacheHandler;
use cacheData;
# instantiate the class
my $h=cacheHandler->new();
my $d=cacheData->new();
# add cacheData to handler
$h->add($d);
# remove cachedata from handler
$h->remove($d);
# get a cacheData-instance
my $cdi=$h->get("myID");
# reset iterating over list of cacheData-instances
$h->resetGetNext();
# get next cacheData-instance in list until end of list
while (my $cdi=$h->getNext()) {
print "My cacheData ID: ".$cdi->id()."\n";
}
# check if cacheData-instance exists in list or not
if ($h->exists("MyID")) { print "Exists!\n"; }
# load saved cache into cacheHandler-instance
$h->load();
# save cache in cacheHandler-instance to file
$h->save();
# check if cacheData has been updated in handler
if ($h->updated()) { print "List has been updated!\n"; }
# get last error message
my $msg=$h->error();
Class to handle a list of cacheData-instances that contain data that an AURORA application needs to keep. Enables one to add, remove, check for existence, get and load- and save the cache to/from a file.
Instantiates the class.
Accepts the following parameters:
location Sets the location or path of the cache-file that the class writes. SCALAR. Optional. If not specified, it defaults to the contents of the environment-variable "AURORA_PATH" and if that is not specified it is set to "/local/app/aurora".
The filename of the cache-file is set to "mainsrvc.cache".
Returns the class-instance.
Adds a cacheData-object to the cacheHandler.
Accepts only one parameters: data. The data-parameter must be a reference to a cacheData-instance or else this method fails.
Sets the updated-attribute of the class to 1 upon success signalling that the data contained in the handler has changed.
Returns 1 upon success, 0 upon failure. Please check the error()-method for more information upon failure.
Gets a specific cacheData-object.
Accepts only one parameter: id. ID is the textual unqiue ID of the cacheData-instance to fetch if it is in the cacheHandler at all.
Returns the cacheData-instance upon success, undef upon failure. Please check the error()-method for more information upon failure.
Resets the getting next cacheData-instance from the class's list of data.
Resets the pointer in the class list of cacheData-instances and starts from the beginning again.
No input is accepted. Always returns 1.
Gets the next cacheData-instance in the list.
No input is accepted.
Returns the cacheData-instance upon success, or undef if there are no more instances to fetch.
Removes a cacheData-instance from the list of the class.
One input parameter is accepted: either cacheData- ID or instance.
Returns 1 upon success, 0 upon failure. Please check the error()-method for more information upon failure.
Checks if a cacheData-instance exists or not in the class list?
Accepts one input: either cacheData ID or instance.
Returns 1 if the cacheData-instance in question are in the class list, or 0 if not.
Loads cached data from a file.
Accepts one parameter: location. SCALAR. Optional. If not specified will use the location-setting from the new()-method or set through the location()-method (see the new()-method).
Attempts to load the saved cache from a file. The file format is YAML and it will attempt to convert the YAML data into perl data structures.
It will overwrite any cache that are already present in the cacheHandler-instance.
Returns 1 upon success, 0 upon failure. Please check the error()-method for more information upon failure.
Saves the cacheData list of the cacheHandler to a file.
Accepts only one input: location. SCALAR. Optional. If not specified will use the location-setting from the new()-method (see the new()-method).
The method will only save the data if the data has changed. It checks this by calling the updated()-method to see if the cacheHandler-instance data has changed (either by add or remove). After the data has been successfully written to file it resets the updated-status to false. This mechanism makes it possible to more often and repeatedly call the save()-method without it actually triggering unnecessary I/O-operations.
The cacheData-list of the cacheHandler is saved in YAML-format.
This method returns 1 upon success, 0 upon failure. Please check the error()-method for more information upon failure.
Get or set the location of the cache-file.
Accepts one input if is a set-operation: location. SCALAR. Required if set-operation. Sets the location of where the cache-file resides, which are used by the load()- and save()-methods.
Returns the location-setting upon a set-operation.
Checks if the data in the cacheHandler-instance has been updated or not?
No input accepted.
Returns 1 if updated, 0 if not.
Get the last error from the class.
No input is accepted.
Returns a SCALAR with the last error message, if any.