cache.func.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->func('cache.' . cache_type());
  8. function cache_type() {
  9. global $_W;
  10. $cacher = $connect = '';
  11. $cache_type = strtolower($_W['config']['setting']['cache']);
  12. if (extension_loaded($cache_type)) {
  13. $config = $_W['config']['setting'][$cache_type];
  14. if (!empty($config['server']) && !empty($config['port'])) {
  15. if ($cache_type == 'memcache') {
  16. $cacher = new Memcache();
  17. } elseif ($cache_type == 'redis') {
  18. $cacher = new Redis();
  19. }
  20. $connect = $cacher->connect($config['server'], $config['port']);
  21. }
  22. }
  23. if (empty($cacher) || empty($connect)) {
  24. $cache_type = 'mysql';
  25. }
  26. return $cache_type;
  27. }
  28. function cache_load($key, $unserialize = false) {
  29. global $_W;
  30. static $we7_cache;
  31. if (!empty($we7_cache[$key])) {
  32. return $we7_cache[$key];
  33. }
  34. $data = $we7_cache[$key] = cache_read($key);
  35. if ($key == 'setting') {
  36. $_W['setting'] = $data;
  37. return $_W['setting'];
  38. } elseif ($key == 'modules') {
  39. $_W['modules'] = $data;
  40. return $_W['modules'];
  41. } elseif ($key == 'module_receive_enable' && empty($data)) {
  42. cache_build_module_subscribe_type();
  43. return cache_read($key);
  44. } else {
  45. return $unserialize ? iunserializer($data) : $data;
  46. }
  47. }
  48. function cache_system_key($cache_key) {
  49. $args = func_get_args();
  50. switch (func_num_args()) {
  51. case 1:
  52. break;
  53. case 2:
  54. $cache_key = sprintf($cache_key, $args[1]);
  55. break;
  56. case 3:
  57. $cache_key = sprintf($cache_key, $args[1], $args[2]);
  58. break;
  59. case 4:
  60. $cache_key = sprintf($cache_key, $args[1], $args[2], $args[3]);
  61. break;
  62. case 5:
  63. $cache_key = sprintf($cache_key, $args[1], $args[2], $args[3], $args[4]);
  64. break;
  65. case 6:
  66. $cache_key = sprintf($cache_key, $args[1], $args[2], $args[3], $args[4], $args[5]);
  67. break;
  68. }
  69. $cache_key = 'we7:' . $cache_key;
  70. if (strlen($cache_key) > CACHE_KEY_LENGTH) {
  71. trigger_error('Cache name is over the maximum length');
  72. }
  73. return $cache_key;
  74. }
  75. function &cache_global($key) {
  76. }