Download the PHP package juneym/zf2-cache-mongo without Composer

On this page you can find all versions of the php package juneym/zf2-cache-mongo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package zf2-cache-mongo

zf2-cache-mongo

ZF2 cache storage compatible library using MongoDB's TTL collection

Overview

It seems that there aren't that many people out there who is interested in creating a ZF2 compatible cache storage backend library for MongoDB, hence this project.

The library utilizes the Time To Live (TTL) collection feature introduced in MongoDB v2.2

Using the Library

  1. Update your composer.json (if you have)

    (to be added)        
  2. Instantiate the library

    $options = array(
      'dsn' => 'mongodb://127.0.0.1',
      'mongoOptions' => array(/* any of the valid \Mongo or \MongoClient options */),
      'dbname' => 'cachedb',
      'collection' => 'cache',
      'ttl' => 10,
      'namespace' => 'stl'
    );
    
    $mongoCache = new \Juneym\Cache\Storage\Adapter\Mongo($options);
    $cacheKey = md5('This is a sample key');
    
    $created = $mongoCache->setItem($cacheKey, array('x' => 12345, 'y' => 'ABCDEF' . rand(0,10000)));
    if (!$created) {
        die("Cached using key: " . $cacheKey . "\n");
    } 
    
    $data = $mongoCache->getItem($cacheKey);
    print_r($data);
    unset($mongoCache);

Cache Item Attributes

There are applications that require additional metadata as part of the cache record in MongoDB such as "current page addres" or "remote host ip". To do this, use the setCacheItemAttributes(array) to attach an array attributes to a cache item. When the item is retrieve with an attribute, the data is accessible via the attr key. Following is a snippet from the tests file.

About TTL Index & Cache Expiry

There are two ways a cached data will expire.

  1. When the difference between the current time and the cache item's created time is more than the cache item's ttl value (in seconds)
  2. When the record's created value is way past the MongoDB's cache collection TTL index (expireAfterSeconds). Note that MongoDB's garbage collection runs every 60 seconds so don't be surprised if the cached item is still available. MongoDB's garbage collector will eventually remove all qualified records in the background.

Required Index

Assuming that the cache database is called "cachedb" and the collection name is "cache", fhe following indexes are required:

use cachedb
db.cache.ensureIndex({ns:1}, {background:true});
db.cache.ensureIndex({ns:1, key:1}, {background:true});
db.cache.ensureIndex({ns:1, tags:1}, {background:true});

If you are using version below v0.2.0, please use the following TTL index definition:

db.cache.ensureIndex({created:1}, {background:true, expireAfterSeconds: 3600, name: 'colRecordTTl'});

Starting in v0.2.0, the expireAt field is populated based on the ttl value at the time the cache entry has been created (or saved). Use the following index to enforce automatic expiration of record based on expireAt field.

db.cache.ensureIndex({created:1, expireAt:1}, {background: true});
db.cache.ensureIndex({expireAt:1}, {expireAfterSeconds: 0, name: 'cache_expire_at'});

All versions of zf2-cache-mongo with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.23
zendframework/zend-cache Version 2.4.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package juneym/zf2-cache-mongo contains the following files

Loading the files please wait ....