Commit 1b15ca61 authored by Cobra_Fast's avatar Cobra_Fast

Update README.md

parent 436d3134
......@@ -157,6 +157,8 @@ $d = OOPHelper::Cast($c, 'foo'); // __castedDown will be called, since bar->c co
Provides key-value (and arbitrary object) caching in named stores.
Intended to be used in webserver scripts with a short lifetime as it abuses a global variable (`$___transientcache`) to store all instances. Works well in `DbThing->Select($id)` kind of situations where the same object might be needed several times.
The cache can be disabled (i.e. made to always miss) by setting the constant `DISABLE_TRANSIENT_CACHE` to a truey value.
```php
function FetchObject($request_id)
{
......@@ -173,7 +175,22 @@ function FetchObject($request_id)
}
```
The cache can be disabled (i.e. made to always miss) by setting the constant `DISABLE_TRANSIENT_CACHE` to a truey value.
Above code does not need to be boilerplated (as much) as there is a handy method that does the same thing.
Note: The result fetching function should return `false` on fetch miss.
```php
function FetchObject($request_id)
{
return TransientCache::Load("example")->Cache(
$request_id,
function ($mysqlihelper) use ($request_id)
{
return ($r = $mysqlihelper->Query('SELECT * FROM things WHERE id = ?', $request_id)) instanceof mysqli_result
&& $r->num_rows > 0 ? $r->fetch_object() : false;
},
array($this->getMysqli())
);
}
```
## Data
### MySQLiHelper
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment