Download the PHP package emag-tech-labs/annotation-cache-bundle without Composer

On this page you can find all versions of the php package emag-tech-labs/annotation-cache-bundle. 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 annotation-cache-bundle

Annotation Cache Bundle

Packagist Version Build Status Total Downloads Latest Stable Version License Coverage Status


Annotation based caching for method responses in services inside a Symfony container.

This bundle helps you to add caching with a simple annotation or attribute. You can store the cache in any class that implements PSR-6: Caching Interface be it a simple array or a redis/memcache storage.

How it works

This bundle will scan all the methods from the defined services and look for the Cache annotation or attribute (for PHP 8+).

For all the services where the Cache annotation/attribute is found, it will create a proxy class (using ocramius/proxy-manager) that extends the service class, include the CacheableClassTrait and overwrite the methods that have the Cache annotation/attribute.

The overwritten methods consist of a call to the getCached method that identifies the annotation details, gets the key, gets the Cache PSR-6 implementation and then gets the result from cache. If no data with the generated cache key is found, it will call the original method and then save the response in the given provider.

The bundle has a CompilerPass implementation that will search and overwrite the service definition with the proxy class created in the process explained above.

Installation

With Symfony Flex

The easiest way to install and configure the AnnotationCacheBundle with Symfony is by using Symfony Flex:

Symfony Flex will automatically register and configure the bundle.

Without Symfony Flex

If your application does not use Symfony Flex you can configure the bundle manually by following the steps below

Step 1: Download the bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

Step 2: Enable the bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

Step 3: Configuration

The easiest way is to dump the config and copy it to configs/packages/emag_annotation_cache.yaml.

Configuration example

You have to configure the name of the service that is PSR6 compliant, that means it will have to implement Psr\Cache\CacheItemPoolInterface:

Usage

Add the Cache annotation for the methods you want to cache.

Annotation parameters:

Annotations defined with Doctrine Annotations library

Example

Annotations defined with PHP 8 attributes

Example

Use cases

Below you can find two ways you can use this Bundle

Config

Service Code

This bundle can be used in multiple ways, two of them are shown below.

The first case is the most common one, where you have a method that does multiple time-consuming operations, and you want to cache the response in redis with a prefix (simple_time_consumingoperation) for a given time (60s in the case below). The logic here is to look for the value in redis, and if not found, run the actual method, get the result and cache it for further use taking into account the arguments passed in the @Cache annotation.

The second case could be used if you want to generate the cache in a command and have it already warmed up, or maybe update the cache when a certain event is triggered, or you update the information in a database. Based on the example below, you could set a cron to run every ~3000 seconds and that will recreate the cache before it expires. Because we are using the same cache prefix and keys, when the same argument values are passed for both methods(getTimeConsumingOperationValueWithReset and getTimeConsumingOperationValue), the generated cache key will be the same, in this case: time_consuming_operation_7fe49b314fb356bee76dbd3b8716b4d5ab5db600. That means that both methods will write (and read) the cache in (from) the same cache key. Because the second method has the reset argument set to true, any call to the second method will overwrite the cache value in the key time_consuming_operation_7fe49b314fb356bee76dbd3b8716b4d5ab5db600 with the new result of the function.

Service calls

Contributing

Thanks for your interest in contributing! There are many ways to contribute to this project. Get started here.


All versions of annotation-cache-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
psr/cache Version ^1.0|^2.0|^3.0
psr/log Version ^1.1|^2.0|^3.0
symfony/dependency-injection Version ^4.0||^5.1||^6.0
symfony/yaml Version ^4.0||^5.1||^6.0
friendsofphp/proxy-manager-lts Version ^1.0
doctrine/annotations Version ^1.11
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 emag-tech-labs/annotation-cache-bundle contains the following files

Loading the files please wait ....