Cache
class Cache
A very simple Cache - currently implemented in session
Someday we will build a better cache but for now this simply saves re-retrieving or re-constructing a few bits of user data later in the same request or in a later request. Everything is saved in $_SESSION.
Since the cache is in $_SESSION, it is already per user, per link_id. And within that we have "cache locations". Each location, can have one key and one value. We have this limitation because we don't want our simple session based cache to grow forever. Each location stores only one entry.
For example in the loadUserInfoByPass() routine, we are looking at users other than our own (usually as instructor). To make sure we only make the SQL query once, we make the following call:
Cache::set('lti_user', $user_id, $row);
This will overwrite any other user_id value in the 'lti_user' slot. In effect there is one 'lti_user' slot and we store a a key (which might change) from call to call and a value (the row of retrieved data).
This strictly bounds overall cache data in the session to the number of cache locations and avoids any need for a garbage collection or an independent expire process.
Methods
Place an entry in the cache.
Check and return a value from the cache.
Check when value in the cache expires
Delete an entry from the cache.
Details
at line 43
static
set($cacheloc, $cachekey, $cacheval, $expiresec = false)
Place an entry in the cache.
We don't cache null or false if that was our value.
at line 59
static
check($cacheloc, $cachekey)
Check and return a value from the cache.
Returns false if there is no entry.
at line 82
static
expires($cacheloc, $cachekey)
Check when value in the cache expires
Returns false if there is no entry.
at line 101
static
clear($cacheloc)
Delete an entry from the cache.