- Direct superclass:\datasource\DataSource
- Direct known subclasses:
The fast objects, also called AFO (Access Fast Object) are used as multi-level caches.
A fast object is generally a serialized standarized object.
They are a 3-level cache of any type of information:
- An original portable fast object, kept in any support (file, database, downloadable over network, etc.).
- A first cache into the shared memory.
- A second cache directly into the object as a local information fastly accesible.
The original fast object should be accesible with read/write/unlink access, and should have a write time available too.
However, the fast object may be read only too.
The shared memory cache is optional but highly recommended to not read the source on each page hit (only the timestamp stat).
The memory is loaded when the data is needed with read() method.
To create a fast object, you need a \datasource\DataSource instance (generally a \datasource\FileSource) and a \datasource\SHMSource instance.
The fast object will be charged to always be consistant and synchronized with the origin, but save a lot of access time.
unlink will physically deletes the source file if write access is granted.
3.1. Contructor:\datasource\FastObjectSource($datasource, $shmsource)
Creates the instance.
- $datasource: \datasource\DataSource extended instance, the origin of our fast object.
- $shmsource: \datasource\SHMSource instance, the shared memory instance to stock the fast object.
If the datasource does not exists, the object will be invalid until the file is created.
If the shared memory or the local memory is empty or desynchronized (creation time before the origin creation time) then object will be invalid until synchronization.
There is no constant into this class.
3.3. Attributes:protected DataSource $datasource
Is used to store the datasource instance.protected SHMSource $shmsource
Is used to store the shared memory instance.protected boolean $loaded
Is used to know if the fast object data is in local memory.
false means the data is not loaded yet.
3.4. Methods:public boolean static isValid()
This method is used to know if the data into the FastObjectSource is valid or not.
If the datasource is invalid, the object will be invalid until the source is created.
If the shared memory or the local memory is empty or desynchronized (creation time before the origin creation time) then the object will be invalid until synchronization (generally when read).public integer getTimeStamp()
This method is used to get the last write access to the local information data.
If the object has no local data yet, it will return null.
Note: The returned value is a unix timestamp that you can format to a human readable date with date().public mixed read()
This method is used to read our fast object.
If the datasource object is invalid (file not accesible), it will return null.
if the datasource object is valid and available, the 3 levels of the fast object will be synchronized.public void write($data)
This method is used to write the data into our fast object.
The 3 levels of the fast object will be synchronized.
public void unlink()
- $data: string, the data to write in the fast object.
This method is used to physically deletes the fast object.
The object becomes invalid.