cache_sql.php 1004 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: cache_sql.php 24721 2011-10-09 10:30:22Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class ultrax_cache {
  12. function ultrax_cache($conf) {
  13. $this->conf = $conf;
  14. }
  15. function get_cache($key) {
  16. static $data = null;
  17. if(!isset($data[$key])) {
  18. $cache = C::t('common_cache')->fetch($key);
  19. if(!$cache) {
  20. return false;
  21. }
  22. $data[$key] = unserialize($cache['cachevalue']);
  23. if($cache['life'] && ($cache['dateline'] < time() - $data[$key]['life'])) {
  24. return false;
  25. }
  26. }
  27. return $data[$key]['data'];
  28. }
  29. function set_cache($key, $value, $life) {
  30. $data = array(
  31. 'cachekey' => $key,
  32. 'cachevalue' => serialize(array('data' => $value, 'life' => $life)),
  33. 'dateline' => time(),
  34. );
  35. return C::t('common_cache')->insert($data);
  36. }
  37. function del_cache($key) {
  38. return C::t('common_cache')->delete($key);
  39. }
  40. }