Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report

symfony/cache v7.0.6

Provides extended PSR-6, PSR-16 (and tags) implementations
Package summary
Share
0
issues
0
licenses
Package created
19 Jan 2016
Version published
27 Mar 2024
Maintainers
1
Total deps
0
Direct deps
0
License
MIT
Generating a report...
Hold on while we generate a fresh audit report for this package.

Frequently Asked Questions

What does symfony/cache do?

Symfony/Cache is a powerful component used to add cache to your applications. Following the PSR-6 and PSR-16 caching standards, Symfony/Cache is designed for speed and low overhead to make caching faster and more efficient. It's packed with adapters for the most common caching backends and also provides implementations for Symfony's CacheInterface and TagAwareCacheInterface from the symfony/cache-contracts package. Leveraging caching in your applications can greatly improve performance by storing data in a cache for faster future access.

How do you use symfony/cache?

To use symfony/cache, first, you need to install it via composer. Run composer require symfony/cache. This command installs the symfony/cache package into your project.

Here is an example of how to use the cache component:

use Symfony\Contracts\Cache\ItemInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

// The first argument is the namespace, which should be unique per cache pool
// The second argument is the default lifetime of cache items, in seconds
$cache = new FilesystemAdapter('my_cache_namespace', 3600);

// Attempt to fetch the cached value
$value = $cache->get('my_cache_key', function (ItemInterface $item) {
    $item->expiresAfter(3600);

    // do some expensive computation or fetch data
    // and finally return the computed value
    return "cached value";
});

echo $value;  // Output: "cached value"

In this example, we first create an instance of FilesystemAdapter which represents the cache pool. Next, we attempt to fetch a value from the cache using the get() method. If the value does not exist in the cache, we use a callback function to compute and return the value, which gets stored in the cache.

Where are the symfony/cache docs?

For detailed usage and examples, you can refer to the official Symfony Cache component documentation by visiting Symfony's official documentation. You can also contribute, report issues and send pull requests in the main Symfony repository. The symfony/cache package follows Symfony's code of conduct and contributing guidelines.