Skip to content

Commit

Permalink
Removed memcache
Browse files Browse the repository at this point in the history
  • Loading branch information
bxjx committed Feb 26, 2013
1 parent 3c4166f commit f12d9ad
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 21 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"silex/silex": "1.0.*",
"twig/twig": "1.*",
"sendgrid/sendgrid-php": "dev-master",
"mheap/Silex-Memcache": "*",
"andylockran/createsend-php": "*",
"monolog/monolog": "1.2.*"
},
Expand All @@ -14,4 +13,4 @@
"Sly": "vendor/sly/url-shortener-bundle/"
}
}
}
}
9 changes: 1 addition & 8 deletions src/DGM/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ public function register(Application $app)
'monolog.appname' => 'budget2012'
]);

$app->register(new \SilexMemcache\MemcacheExtension(), [
'memcache.library' => 'memcached',
'servers' => [
['localhost', '11211']
]
]);

$app->register(new \Silex\Provider\TwigServiceProvider(), [
'twig.path' => __DIR__.'/../../templates',
]);
Expand All @@ -101,7 +94,7 @@ public function register(Application $app)
public function boot(Application $app)
{
$app['averageBudget'] = $app->share(function(Application $app) {
return (new \DGM\Service\AverageBudget($app['budgets'], $app['memcache']))->getAverageBudget();
return (new \DGM\Service\AverageBudget($app['budgets']))->getAverageBudget();
});
}

Expand Down
14 changes: 3 additions & 11 deletions src/DGM/Service/AverageBudget.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,19 @@ class AverageBudget
{

private $budgets;
private $memcached;

const EXPIRES = 600; // 10 minutes
const CACHE_KEY = 'averageBudget';

public function __construct(Budgets $budgets, \Memcached $memcached)
public function __construct(Budgets $budgets)
{
$this->budgets = $budgets;
$this->memcached = $memcached;
}

public function getAverageBudget()
{
$averageBudget = $this->memcached->get(self::CACHE_KEY);

if ($this->memcached->getResultCode() == \Memcached::RES_NOTFOUND) {
$averageBudget = $this->budgets->getAverageBudget();
$this->memcached->set(self::CACHE_KEY, $averageBudget, self::EXPIRES);
}

$averageBudget = $this->budgets->getAverageBudget();
return $averageBudget;
}

}
}

0 comments on commit f12d9ad

Please sign in to comment.