Skip to content

Instantly share code, notes, and snippets.

@mklooss
Created November 24, 2013 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mklooss/7626105 to your computer and use it in GitHub Desktop.
Save mklooss/7626105 to your computer and use it in GitHub Desktop.
Magento - MongoDB Cache cleaner for https://github.com/colinmollenhour/Cm_Cache_Backend_Mongo
<?php
$cfg = array(
'server' => 'mongodb://127.0.0.1:27017/?journal=false&w=1&wTimeoutMS=20000',
'db' => 'cm_cache',
'collection' => 'cm_cache'
);
// set to timezone to UTC, like magento do this
date_default_timezone_set('UTC');
$conn = new MongoClient($cfg['server']);
$db = $conn->selectDB($cfg['db']);
$collection = $db->selectCollection($cfg['collection']);
// remove old cache
$collection->remove(array('e' => array('$lte' => new MongoDate())));
// Delete data older than 1 month
$time = strtotime('-1 month');
$collection->remove(array('m' => array('$lte' => new MongoDate($time))));
echo "complete";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment