The WebAbility® Network Developers - Documentation
WebAbility Site
\datasource\TemplateSource reference

I. Structure:


- namespace:
\datasource\

- Direct superclass:
\datasource\DataSource

- Direct known subclasses:
none

II. Description:


The template source is an example of 4-level cache, using an origin source, a fast object and a shared memory cache.
The origin source is generally a human readable file (in the case of the template, it's an HTML file with macrolanguage inside). The fast object is a serialized version of the compiled file, and the local memory is an array of value directly usable.

The 4 levels cache are:
- An origin HTML template data source, kept in any support (file, database, downloadable over network, etc.).
- A first serialized cache portable fast object, kept in any support (file, database, downloadable over network, etc.).
- A second serialized cache into the shared memory.
- A third array cache directly into the object as a local information fastly accesible.

The origin source is a template file, i.e. a raw not compiled file containing HTML and Macrolanguage. Compiling the file into a computer readable format is a time and i/o access consumer. This task will be done only when the original HTML file is modified.
The fast object read is also a time and i/o cosumer, and will be read only when it desynchronizes with the original source.
The shared memory cache is optional but highly recommended to not read the fast object on each page hit (only the timestamp stat).
The memory is loaded when the data is needed with read() method.

To create a template object, you need a \datasource\DataSource origin instance (generally a \datasource\FileSource) and a \datasource\FastObjectSource instance.
The fast object will be charged to always be consistant and synchronized with the origin, but save a lot of access and CPU time.

unlink will physically deletes the origin source file, afo file and shared memory if write access is granted.

The Macrolanguage is a specific set of keywords to control the template and integrate the data into the template.
Please check the \core\WATemplate documentation for a detailed manual of the Macrolanguage.


III. Reference:


3.1. Contructor:


\datasource\TemplateSource($originsource, $fastobjectsource)
Creates the instance.
  • $originsource: \datasource\DataSource extended instance, the origin of our Template file.
  • $fastobjectsource: \datasource\FastObjectSource instance, the instance to stock the fast object and shared memory.
If the originsource does not exists, the object will be invalid until the file is created.
If the fast object, 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.


3.2. Constants:

There is no constant into this class.


3.3. Attributes:


protected DataSource $originsource
Is used to store the origin datasource instance.

protected FastObjectSource $fastobjectsource
Is used to store the fast object instance.

protected boolean $loaded
Is used to know if the template 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 TemplateSource is valid or not.
If the originsource is invalid, the object will be invalid until the source is created.
If the fast object or the local memory are empty or desynchronized (creation time before the origin creation time) then the object will be invalid until synchronization (generally when read or write).

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 WATemplate read()
This method is used to read our template.
If the origin source object is invalid (file not accesible), it will return null.
if the origin source object is valid and available, the 4 levels of the template object will be synchronized.

public void write($data)
This method is used to write the data into our template object.
The 4 levels of the fast object will be synchronized.
  • $data: string, the template.

public void unlink()
This method is used to physically deletes the template object, fast object and shared memory variable.
The object becomes invalid.