Skip to content

Latest commit

 

History

History
74 lines (56 loc) · 1.11 KB

cache.md

File metadata and controls

74 lines (56 loc) · 1.11 KB

Cache

@Cache annotation allows cache management.

namespace MyProject\AClass;

use OpenClassrooms\ServiceProxy\Annotation\Cache;

class AClass
{
    /**
     * @Cache 
     *
     * @return mixed
     */
    public function aMethod($aParameter)
    {
        // do things
        
        return $data;
    }
}

The id is equal to: md5('MyProject\AClass::aMethod::'.serialize($aParameter)) and the TTL is the default.

Options:

Lifetime:

/**
 * @Cache(lifetime=1000)
 * Add a TTL of 1000 seconds
 */

Id (key):

/**
 * @Cache(id="'key'")
 * Set the id to "key"
 */

Supports Symfony ExpressionLanguage, for example:

/**
 * @Cache(id="'key' ~ aParameter.field")
 * Set the id to 'key'.$aParameter->field
 */

Namespace:

/**
 * @Cache(namespace="'namespace'")
 * Add a namespace to the id with a namespace id equals to "namespace" 
 */

Supports Symfony ExpressionLanguage, for example:

/**
 * @Cache(namespace="'namespace' ~ aParameter.field")
 * Add a namespace to the id with a namespace id equals to 'namespace'.$aParameter->field
 */