Cache.class.php
33 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @copyright Copyright (c) 2011 Quality Unit s.r.o. |
| 4 | * @author Juraj Simon |
| 5 | * @package WpPostAffiliateProPlugin |
| 6 | * @since version 1.0.0 |
| 7 | * |
| 8 | * Licensed under GPL2 |
| 9 | */ |
| 10 | |
| 11 | class Shortcode_Cache { |
| 12 | |
| 13 | private function getCahce() { |
| 14 | return unserialize(get_option(Shortcode_Affiliate::AFFILAITE_SHORTCODE_CACHE)); |
| 15 | } |
| 16 | |
| 17 | public function update($username, $sessionid) { |
| 18 | $cache = $this->getCahce(); |
| 19 | $cache[$username] = array('sessionid' => $sessionid, 'created' => time()); |
| 20 | update_option(Shortcode_Affiliate::AFFILAITE_SHORTCODE_CACHE, serialize($cache)); |
| 21 | } |
| 22 | |
| 23 | public function getSessionId($username) { |
| 24 | $cache = $this->getCahce(); |
| 25 | if ($cache == null) { |
| 26 | return null; |
| 27 | } |
| 28 | if (array_key_exists($username, $cache) && (time() - $cache[$username]['created'] < 120)) { |
| 29 | return $cache[$username]['sessionid']; |
| 30 | } |
| 31 | return null; |
| 32 | } |
| 33 | } |