|
4. Size Cache Overview
To implement
the Size Cache, you must:
- implement the
Cache interface
- implement a class
to carry out the logic of "size-based invalidation"
4.1. Implementing the Cache interface
The following code
implements some methods in the Cache API.
PluginCache
| Class Name |
oracle.reports.plugin.cache.size.PluginCache |
| Description |
This
is the implementation of the Cache interface |
| implements |
oracle.reports.cache.Cache |
1. newItem(job,
instanceKey)
This method creates
a new item in cache system for the given job.
2. deleteItem(item)
This method deletes
the cache item referred to by the parameter item.
3. findItem(jobProps)
This method gets
the job properties and matches them with earlier job request.
It returns the matching report output from cache. It returns
null if a matching item is not found.
4.2. Implement the class for size-based invalidation
The following code
handles the implementation ofthe SizeCache class. This class
ensures that the limit sizeCache is respected by deleting files
from cache directory. You can reuse this class to implement
your custom logic for maintaining the Cache size within specified
limits.
SizeCache
The default cache
logic used in Oracle Reports is FIFO (first-in first-out). As
an example, when the cache hits the maximum size limit, the
oldest file in the cache directory is identified and deleted.
This step is repeated until size of the cache reaches the specified
limit, or until there are no more files in the cache (whichever
condition occurs earlier). This logic is useful in situations
where you do not need to keep cached copies of your old reports.
For example, if you are using Oracle Reports to generate monthly
reports of rented out books in your library, and you are not
interested in keeping the cached copies of your old reports,
you can use the default FIFO logic to manage the cache size.
On the other hand,
the SizeCache class implements the "delete biggest 5 files"
logic to maintain the Cache size limit. As an example, suppose
the cache hits the maximum size limit when the 10th file is
written to the cache directory. At this time, this class will
identify the biggest 5 files in the cache, and delete them.
The SizeCache logic
has less overhead than the default logic. Once the biggest 5
files are deleted, chances are that files will not need to be
deleted for a while. However, this logic comes with a compromise
- in this logic, it is possible that the cached copy of the
latest report is deleted because it is a large report. Note
that the "delete biggest 5 files" logic has been chosen
only to show a sample implementation of Cache class.
You have to implement
the logic that suits your particular situation.
| Class Name |
oracle.reports.plugin.cache.size.SizeCache |
| Description |
This
class implements the "delete biggest 5 files"
logic to maintain the Cache size limit. |
1. start(props,
trace)
This method Starts
the Oracle9i Reports caching service. You can use this method
to set all static information that you can load from the Reports
Server configuration file. (server.conf file in the $ORACLE_HOME/reports/config
directory). This method receives the properties object as a
parameter, which contains the list of values in the configuration
file. The following information is loaded from the properties
object:
- maximum size of
the cache
- maximum number
of files in the cache
- cache directory
If the cache directory
does not exist, it creates the directory.
2. manage()
This
method deletes top 5 items from the cache directory based on
the "biggest file size" logic. The logic is implemented
as:
First check if either
of the parameters - cache size or the maximum number of files
allowed in cache - has been exceeded. If yes, iterate through
the files in the cache directory, identify the biggest 5 files
and delete them. Repeat this step until the size of the cache
reaches the specified limit, or until there are no more files
in the cache (whichever condition occurs earlier).
It is the manage()
method that you will need to override to implement your own
cache-maintenance logic.
3. empty()
It invokes the method
deleteItem repetitively to delete all items in the cache.
|