Is the container rebuilt at each request in Symfony 2 dev mode -


when creating own service, looks object created each time.

service :

services:    plbcache:     class: robusta\plbbundle\cache\lrucache     arguments: [10, %timeout%, %enablecache%] 

class :

class lrucache {    public function __construct($capacity=10, $timeout=-1, $enabled=true) {         echo "creating cache"; // appear @ each request         $this->capacity = $capacity;         $this->timeout = $timeout;         $this->enabled = $enabled;   } } 

obviously, have problem test if objects in cache if cache object rebuilt each time.

for have understood, service container of symfony singleton , default gives singletons - thought can configured prototypes or clients sessions. should give me same services objects after each request.

i have seen in docs container rebuild in dev environment. did miss something, or code wrong ? how prevent dev mode rebuilding cache object ?

container doesn't share instances between requests. each request independent can share data through session (for instance). btw objects created during single request destroyed once finishes. next request every object need created again.

so while services threated (by default can change behaviour) singleton, should consider them "singleton within same request". make notice php behaviour , not symfony-strictly one.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -