Cache.class.php
23 lines
| 1 | <?php |
| 2 | class Shortcode_Cache { |
| 3 | private function getCache() { |
| 4 | return unserialize(get_option(Shortcode_Affiliate::AFFILAITE_SHORTCODE_CACHE)); |
| 5 | } |
| 6 | |
| 7 | public function update($username, $sessionid) { |
| 8 | $cache = $this->getCache(); |
| 9 | $cache[$username] = array('sessionid' => $sessionid, 'created' => time()); |
| 10 | update_option(Shortcode_Affiliate::AFFILAITE_SHORTCODE_CACHE, serialize($cache)); |
| 11 | } |
| 12 | |
| 13 | public function getSessionId($username) { |
| 14 | $cache = $this->getCache(); |
| 15 | if ($cache == null) { |
| 16 | return null; |
| 17 | } |
| 18 | if (array_key_exists($username, $cache) && (time() - $cache[$username]['created'] < 120)) { |
| 19 | return $cache[$username]['sessionid']; |
| 20 | } |
| 21 | return null; |
| 22 | } |
| 23 | } |