diff --git a/db/jig/mapper.php b/db/jig/mapper.php index 52f36acb..ef878f13 100644 --- a/db/jig/mapper.php +++ b/db/jig/mapper.php @@ -153,7 +153,7 @@ function($expr) { * @return static[]|FALSE * @param $filter array * @param $options array - * @param $ttl int + * @param $ttl int|array * @param $log bool **/ function find($filter=NULL,array $options=NULL,$ttl=0,$log=TRUE) { @@ -170,9 +170,12 @@ function find($filter=NULL,array $options=NULL,$ttl=0,$log=TRUE) { $db=$this->db; $now=microtime(TRUE); $data=[]; + $tag=''; + if (is_array($ttl)) + list($ttl,$tag)=$ttl; if (!$fw->CACHE || !$ttl || !($cached=$cache->exists( $hash=$fw->hash($this->db->dir(). - $fw->stringify([$filter,$options])).'.jig',$data)) || + $fw->stringify([$filter,$options])).($tag?'.'.$tag:'').'.jig',$data)) || $cached[0]+$ttlread($this->file); if (is_null($data)) @@ -347,7 +350,7 @@ function reduce($key,$handler,$finalize=null){ * @return int * @param $filter array * @param $options array - * @param $ttl int + * @param $ttl int|array **/ function count($filter=NULL,array $options=NULL,$ttl=0) { $now=microtime(TRUE); diff --git a/db/mongo/mapper.php b/db/mongo/mapper.php index d5645412..4ad4cdfe 100644 --- a/db/mongo/mapper.php +++ b/db/mongo/mapper.php @@ -119,7 +119,7 @@ function cast($obj=NULL) { * @param $fields string * @param $filter array * @param $options array - * @param $ttl int + * @param $ttl int|array **/ function select($fields=NULL,$filter=NULL,array $options=NULL,$ttl=0) { if (!$options) @@ -130,10 +130,13 @@ function select($fields=NULL,$filter=NULL,array $options=NULL,$ttl=0) { 'limit'=>0, 'offset'=>0 ]; + $tag=''; + if (is_array($ttl)) + list($ttl,$tag)=$ttl; $fw=\Base::instance(); $cache=\Cache::instance(); if (!($cached=$cache->exists($hash=$fw->hash($this->db->dsn(). - $fw->stringify([$fields,$filter,$options])).'.mongo', + $fw->stringify([$fields,$filter,$options])).($tag?'.'.$tag:'').'.mongo', $result)) || !$ttl || $cached[0]+$ttlcollection->group( @@ -194,7 +197,7 @@ function select($fields=NULL,$filter=NULL,array $options=NULL,$ttl=0) { * @return static[] * @param $filter array * @param $options array - * @param $ttl int + * @param $ttl int|array **/ function find($filter=NULL,array $options=NULL,$ttl=0) { if (!$options) @@ -213,13 +216,16 @@ function find($filter=NULL,array $options=NULL,$ttl=0) { * @return int * @param $filter array * @param $options array - * @param $ttl int + * @param $ttl int|array **/ function count($filter=NULL,array $options=NULL,$ttl=0) { $fw=\Base::instance(); $cache=\Cache::instance(); + $tag=''; + if (is_array($ttl)) + list($ttl,$tag)=$ttl; if (!($cached=$cache->exists($hash=$fw->hash($fw->stringify( - [$filter])).'.mongo',$result)) || !$ttl || + [$filter])).($tag?'.'.$tag:'').'.mongo',$result)) || !$ttl || $cached[0]+$ttlcollection->count($filter?:[]); if ($fw->CACHE && $ttl)