function get_cache() { try { $cache = new \Doctrine\Common\Cache\FilesystemCache(CACHE_DIR); $cache->save('test.it.ok_or_not', true); return $cache; } catch (\Exception $e) { return new \Doctrine\Common\Cache\ArrayCache(); } }
public function robotsAction(Request $request) { $host = $request->headers->get('host'); $cacheId = 'robots_txt'; $env = $this->get('kernel')->getEnvironment(); $cache = new \Doctrine\Common\Cache\FilesystemCache($_SERVER['DOCUMENT_ROOT'] . '/../app/cache/' . $env . '/sys/' . $host . '/etc/'); //$cache = new \Doctrine\Common\Cache\ApcCache(); if ($fooString = $cache->fetch($cacheId)) { $response = unserialize($fooString); } else { $site = $this->getSite(); if (!$site) { $response = $this->render('CMFTemplateBundle:Status:404.html.twig'); $response->setStatusCode(404); return $response; } $response = new Response(); $response->headers->set('Content-Type', 'text/plain'); $response->sendHeaders(); $response->setContent($site['robots_txt']); $cache->save($cacheId, serialize($response)); } return $response; }
* Return a list of scheduled jobs count grouped by time * Used to populate the cal-heatmap */ $app->get('/api/scheduled-jobs/stats/:start/:end', function ($start, $end) use($app) { $app->response()->header("Content-Type", "application/json"); try { $cacheId = $start . $end; $cacheDriver = new \Doctrine\Common\Cache\FilesystemCache(CACHE . DS . 'scheduled-jobs' . DS . 'stats', '.cache'); if ($cacheDriver->contains($cacheId)) { $jobs = $cacheDriver->fetch($cacheId); } else { $resqueSchedulerStat = new ResqueBoard\Lib\ResqueSchedulerStat(); $jobs = $resqueSchedulerStat->getScheduledJobsCount((int) $start, (int) $end + 60, true); $jobs = json_encode($jobs); if ($start < $end && $end < time()) { $cacheDriver->save($cacheId, $jobs); } } echo $jobs; } catch (\Exception $e) { $app->error($e); } })->conditions(array('start' => '\\d+', 'end' => '\\d+')); $app->get('/api/scheduled-jobs/:start/:end', function ($start, $end) use($app) { $app->response()->header("Content-Type", "application/json"); try { $resqueSchedulerStat = new ResqueBoard\Lib\ResqueSchedulerStat(); $jobs = $resqueSchedulerStat->getJobs((int) $start, (int) $end, true); echo json_encode($jobs); } catch (\Exception $e) { $app->error($e);