00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010 class DAOCache extends DataObjectBase implements ICacheItem {
00011 public $id;
00012 public $key0;
00013 public $key1;
00014 public $key2;
00015 public $content_gzip;
00016 public $data;
00017 public $creationdate;
00018 public $expirationdate;
00019
00020
00021
00022
00023
00024
00025
00026 public function set_keys($keys, $force_where = false) {
00027 $c = count($keys);
00028 if ($c > 3) {
00029 $c = 3;
00030 }
00031 for ($i = 0; $i < $c; $i++) {
00032 $name = 'key' . $i;
00033 if ($force_where) {
00034 $this->add_where($name, '=', $keys[$i]);
00035 }
00036 else {
00037 $val = $keys[$i];
00038 if (!empty($val)) {
00039 $this->$name = $val;
00040 }
00041 else {
00042 $this->add_where($name, DBWhere::OP_IS_NULL);
00043 }
00044 }
00045 }
00046 }
00047
00048
00049
00050
00051
00052
00053 public function get_creationdate() {
00054 return $this->creationdate;
00055 }
00056
00057
00058
00059
00060
00061
00062 public function get_expirationdate() {
00063 return $this->expirationdate;
00064 }
00065
00066
00067
00068
00069
00070
00071 public function get_data() {
00072 return $this->data;
00073 }
00074
00075 public function get_content_plain() {
00076 $ret = $this->content_gzip;
00077 if ($ret && function_exists('gzinflate')) {
00078 $ret = gzinflate($ret);
00079 }
00080 return $ret;
00081 }
00082
00083 public function get_content_compressed() {
00084 return $this->content_gzip;
00085 }
00086
00087 public function set_content_plain($content) {
00088 if (function_exists('gzdeflate')) {
00089 $content = gzdeflate($content, 9);
00090 }
00091 $this->content_gzip = $content;
00092 }
00093
00094 public function set_content_compressed($content) {
00095 $this->content_gzip = $content;
00096 }
00097
00098
00099
00100 protected function create_table_object() {
00101 return new DBTable(
00102 'cache',
00103 array(
00104 new DBFieldInt('id', null, DBFieldInt::AUTOINCREMENT | DBFieldInt::UNSIGNED | DBFieldInt::NOT_NULL),
00105 new DBFieldText('key0', 255),
00106 new DBFieldText('key1', 255),
00107 new DBFieldText('key2', 255),
00108 new DBFieldBlob('content_gzip', DBFieldText::BLOB_LENGTH_LARGE),
00109 new DBFieldDateTime('creationdate', null, DBFieldDateTime::TIMESTAMP),
00110 new DBFieldDateTime('expirationdate', null, DBFieldDateTime::NOT_NULL),
00111 new DBFieldSerialized('data', DBFieldText::BLOB_LENGTH_SMALL)
00112 ),
00113 'id'
00114 );
00115 }
00116
00117
00118
00119
00120
00121
00122
00123 protected function configure_insert_query($query) {
00124 $query->set_policy(DBQueryInsert::IGNORE);
00125 parent::configure_insert_query($query);
00126 }
00127 }