Sparse - Caching and Warnings
Caching
Sparse essentially creates a program out of the templates that you feed
it. The program prints information based on the values it's given,
errors, current page etc. Rather than recomputing the program each
time, Sparse caches it in a file the first time it's computed - meaning
that the template is only parsed the first time it's loaded in
someone's web browser. After that, the program will simply be read from
the cache and executed.
Note that Sparse does not check for the structure of the SQL tables.
Instead, it compares the modified date of the cache file with that of
the script file (i.e. the file that SparseThisPage
or SparsePage
is called from). I.e. if the template file itself is changed, Sparse
will re-parse it. If you want to force Sparse to re-parse the template
(recording new information about your SQL tables), simply modify the actual file and
save it.
By default, Sparse uses the /tmp/ directory for caching. If that
directory doesn't exist, or Sparse doesn't have access to it, it can't
cache the page. The easiest way to know if the cache was successful is
to view the source of the generated HTML page; there should be a
comment at the top saying "Printing from Sparse Cache".
There are two directives you can give Sparse to alter its caching behavior, as follows:
<?php
include('Sparse.php');
define(SPARSE_NOCACHE, 1); //will disable caching entirely
define(SPARSE_DIR, '~/.sparse'); //will set the cache directory
SparseThisPage($_COOKIE['username'], $_COOKIE['password']);
?>
<!--rest of HTML page goes here -->
For the record, the name of the cache file is the full filepath of
the page that calls Sparse, with / and \ replaced by %,
followed by ".sparse".
Remember that PHP must have write access to the caching directory!
Warning Log
Sparse maintains a warning log which indicates any warnings it comes
across. These include required attributes not being given, attributes
not having proper values (e.g. add, edit, or display for sqltemplate type attributes) or e.g. a name attribute referencing a nonexistent field. By default, these are stored in the file /tmp/sparse_warning.log
. Like caching, you can give Sparse two directives to change this, as follows:
<?php
include('Sparse.php');
define(SPARSE_NOWARN, 1); //will disable warning log entirely
define(SPARSE_LOG_FILE, '~/.sparse/sparse_log'); //will set the log file
SparseThisPage($_COOKIE['username'], $_COOKIE['password']);
?>
<!--rest of HTML page goes here -->
Again, remember that PHP must have write access to the warning log.
Previous: Errors | Caching and Warnings | Next: HTML Tag Reference