2016-03-15 16:28:38 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace modl;
|
|
|
|
|
|
|
|
class CacheDAO extends SQL {
|
2016-03-29 14:12:33 +02:00
|
|
|
function get($key) {
|
2016-03-15 16:28:38 +01:00
|
|
|
$this->_sql = '
|
|
|
|
select * from cache
|
2016-03-29 14:12:33 +02:00
|
|
|
where
|
2016-03-15 16:28:38 +01:00
|
|
|
session = :session
|
|
|
|
and name = :name';
|
2016-03-29 14:12:33 +02:00
|
|
|
|
2016-03-15 16:28:38 +01:00
|
|
|
$this->prepare(
|
2016-03-29 14:12:33 +02:00
|
|
|
'Cache',
|
2016-03-15 16:28:38 +01:00
|
|
|
array(
|
2016-03-29 14:12:33 +02:00
|
|
|
'session' => $this->_user,
|
2016-03-15 16:28:38 +01:00
|
|
|
'name' => $key
|
|
|
|
)
|
|
|
|
);
|
2016-03-29 14:12:33 +02:00
|
|
|
|
2016-03-15 16:28:38 +01:00
|
|
|
return $this->run('Cache', 'item');
|
|
|
|
}
|
2016-03-29 14:12:33 +02:00
|
|
|
|
2016-03-15 16:28:38 +01:00
|
|
|
function set(Cache $cache) {
|
|
|
|
$this->_sql = '
|
|
|
|
update cache
|
|
|
|
set data = :data,
|
|
|
|
timestamp = :timestamp
|
|
|
|
where session = :session
|
|
|
|
and name = :name';
|
2016-03-29 14:12:33 +02:00
|
|
|
|
2016-03-15 16:28:38 +01:00
|
|
|
$this->prepare(
|
2016-03-29 14:12:33 +02:00
|
|
|
'Cache',
|
2016-03-15 16:28:38 +01:00
|
|
|
array(
|
2016-03-29 14:12:33 +02:00
|
|
|
'session' => $this->_user,
|
2016-03-15 16:28:38 +01:00
|
|
|
'data' => $cache->data,
|
|
|
|
'timestamp' => $cache->timestamp,
|
|
|
|
'name' => $cache->name
|
|
|
|
)
|
|
|
|
);
|
2016-03-29 14:12:33 +02:00
|
|
|
|
2016-03-15 16:28:38 +01:00
|
|
|
$this->run('Cache');
|
2016-03-29 14:12:33 +02:00
|
|
|
|
2016-03-15 16:28:38 +01:00
|
|
|
if(!$this->_effective) {
|
|
|
|
$this->_sql = '
|
|
|
|
insert into cache
|
|
|
|
(session, name, data, timestamp)
|
|
|
|
values (:session, :name, :data, :timestamp)';
|
2016-03-29 14:12:33 +02:00
|
|
|
|
2016-03-15 16:28:38 +01:00
|
|
|
$this->prepare(
|
2016-03-29 14:12:33 +02:00
|
|
|
'Cache',
|
2016-03-15 16:28:38 +01:00
|
|
|
array(
|
2016-03-29 14:12:33 +02:00
|
|
|
'session' => $this->_user,
|
2016-03-15 16:28:38 +01:00
|
|
|
'name' => $cache->name,
|
|
|
|
'data' => $cache->data,
|
|
|
|
'timestamp' => $cache->timestamp
|
|
|
|
)
|
|
|
|
);
|
2016-03-29 14:12:33 +02:00
|
|
|
|
2016-03-15 16:28:38 +01:00
|
|
|
return $this->run('Cache');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|