public function store($task_object, $unique = false, $priority = 1) { $content = serialize($task_object); $priority = '[' . intval($priority) . ']'; if ($unique) { $hash = '1' . md5($content); return $this->mem->add($hash, $content); } else { $key = $t = $priority . round(microtime(true) * 1000); $i = 0; while ($this->mem->add($key, $content) === false) { $i++; if ($i > 1000) { trigger_error('Can not add key more than 1000 times', E_USER_NOTICE); return false; } $key = $t . $i; } return true; } }