Skip to content

nicklasos/MongoCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoCache

$memcache = new Memcache();
$memcache->connect('localhost', 11211);

$mongo = new Mongo\MongoDB(
    new MongoClient('mongodb://localhost:27017'),
    'dbName',
    new Mongo\Memcache(
        $memcache,
        60 * 30 // 30 mins
    )
);

$collection = $mongo->selectCollection('foo');
$collection->insert(['foo' => 1]);

assert($collection->count() == 1);

$collection->insert(['foo' => 1]);

assert($collection->count() == 1);

sleep(60 * 30 + 1);

assert($collection->count() == 2);


$collection->count(['foo' => 1], ['cache' => false]); // Ignore cache
$collection->count(['foo' => 1], ['cacheTime' => 10]); // Cache result for 10 seconds

###Supported methods

  • count
  • aggregate

About

MongoDB cache

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages