/[drupal]/contributions/modules/cacherouter/CacheRouter.php
ViewVC logotype

Contents of /contributions/modules/cacherouter/CacheRouter.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Fri Dec 26 09:52:36 2008 UTC (11 months ago) by slantview
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +31 -1 lines
File MIME type: text/x-php
Merge with DRUPAL-7--1
1 <?php
2 /**
3 * $Id: CacheRouter.php,v 1.1.2.4 2008/12/26 02:23:54 slantview Exp $
4 *
5 * @file CacheRouter.php
6 * The main class for routing to the cache engines.
7 */
8 require 'Cache.php';
9
10 class CacheRouter {
11 var $map = array();
12 var $settings = array();
13 var $type = array();
14
15 function __construct() {
16 global $conf;
17 $conf['page_cache_fastpath'] = TRUE;
18 }
19
20 private function __init($bin) {
21 global $conf;
22
23 if (isset($conf['cacherouter'][$bin]['engine']) && !isset($this->map[$bin])) {
24 $type = strtolower($conf['cacherouter'][$bin]['engine']);
25 }
26 else {
27 $type = isset($conf['cacherouter']['default']['engine']) ? $conf['cacherouter']['default']['engine'] : 'db';
28 }
29
30 $this->type[$bin] = $type;
31
32 if (!class_exists($type . 'Cache')) {
33 if (!require(dirname(__FILE__) .'/engines/' . $type . '.php')) {
34 return FALSE;
35 }
36 }
37 $cache_engine = $type . 'Cache';
38
39 $this->map[$bin] = new $cache_engine($bin);
40 }
41
42 public function get($key, $bin) {
43 if (!isset($this->map[$bin])) {
44 $this->__init($bin);
45 }
46 return $this->map[$bin]->get($key);
47 }
48
49 public function set($key, $value, $expire, $headers, $bin) {
50 if (!isset($this->map[$bin])) {
51 $this->__init($bin);
52 }
53 return $this->map[$bin]->set($key, $value, $expire, $headers);
54 }
55
56 public function delete($key, $bin) {
57 if (!isset($this->map[$bin])) {
58 $this->__init($bin);
59 }
60 return $this->map[$bin]->delete($key);
61 }
62
63 public function flush($bin) {
64 if (!isset($this->map[$bin])) {
65 $this->__init($bin);
66 }
67 return $this->map[$bin]->flush();
68 }
69
70 public function page_fast_cache($bin) {
71 if (!isset($this->map[$bin])) {
72 $this->__init($bin);
73 }
74 return $this->map[$bin]->page_fast_cache();
75 }
76
77 public function getStats($bin) {
78 $bin = ($bin == 'default') ? 'cache' : $bin;
79
80 if (!isset($this->map[$bin])) {
81 $this->__init($bin);
82 }
83
84 return $this->map[$bin]->stats();
85 }
86
87 public function getBins() {
88 global $conf;
89 return array_keys($conf['cacherouter']);
90 }
91
92 public function getType($bin) {
93 $bin = ($bin == 'default') ? 'cache' : $bin;
94 return $this->type[$bin];
95 }
96 }

  ViewVC Help
Powered by ViewVC 1.1.2