function count($filter = NULL, $ttl = 0)
{
$fw = \Base::instance();
$cache = \Cache::instance();
if (!($cached = $cache->exists($hash = $fw->hash($fw->stringify([$filter])) . '.mongo', $result)) || !$ttl || $cached[0] + $ttl < microtime(TRUE)) {
$result = $this->collection->count($filter ?: []);
if ($fw->get('CACHE') && $ttl) {
// Save to cache backend
$cache->set($hash, $result, $ttl);
}
}
return $result;
}