3

Is there any built in possibility (or an external bundle) to cache data in Symfony2?

I don't want to cache the page itself, but data inside the application, using a simple key -> value store on the file system for example.

1

6 Answers 6

2

There's no built in solution, but I recommend you giving APC, Redis or Memcache a try (they're all in-memory datastores).

Sign up to request clarification or add additional context in comments.

Comments

1

You can use LiipDoctrineCacheBundle to integrate cache drivers from Doctrine common into your Symfony project.

Comments

1

i'm using winzouCacheBundle. it gives you a streamlined cache api on different backends (apc,file,memcache,array,xcache, zenddata).

Comments

0

For now, there is no unique solution for caching in Symfony2. Some parts of the framework use Doctrine Common.

There are discussions about a "standard" caching solution if Symfony2, but we will have to wait for some time...

1 Comment

Now the caching system of doctrine is out of the common github.com/doctrine/cache
0

I think the DoctrineCacheBundle is currently the way to go.

The DoctrineCacheBundle allows your Symfony application to use different caching systems through the Doctrine Cache library.

Docs @ Symfony.com

Code @ Github

Comments

-1

If I understand well, you would like to store data (attached to the session) and reload them when the same session will call again a new controller, in order to avoid to execute the same procedure more times (for example to read a table from a database).

You can use the session system in your controllers:

<?php namespace YourStuff\YourBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; class YourController extends Controller { $session = $this->get("session"); $variabile = 4; $session->set("variableName",$variable); // setter if ($session->has("variableName") // to check if the variable exists { $variableName = $session->get("variableName"); // getter } } 

This is an example; the "variableName" could be accessed next time the same session will be called, if the lifetime of the session is not yet expired.

The "session" uses the __SESSION variable of PHP, so be sure to set correctly the session.cookie_lifetime and session.gc_maxlifetime, in order to give the desired lifetime.

1 Comment

Session is not a cache! Do not abuse it. Use a file or memory cache instead, e.g. filesystem, memcache, reds etc

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.