symfony - Symfony2/Doctrine2 caching stuff to avoid queries -


background: have big table (2000 rows, 10 columns) full of small int (0,1,2 only). given entity , field of entity, depending on values of 10 columns information if want display , or make required field of entity when render form. instead of querying db each field, every time have ->add in form builder, i'd cache whole table "somewhere" in server's memory.

how can that? necessary each user "loads" table, or can done once of users , each user reads server's ram?

that table never changes. still need able upload updated version of every once in while (veeery seldom).

thank you!

sn

all need use useresultcache method.

doctrine uses cache driver set in symfony configuration, when write querybuilder fetching data table tell doctrine want result cached (for how long , under key optional):

class yourentityrepository extends entityrepository {      public function getallrowscached()     {         $cachedresult = $this->createquerybuilder('e')             ->getquery()             ->useresultcache(true, 3600, 'cache_key')             ->getarrayresult();          return $cachedresult;     }  } 

cache common users first user query db, second use data cache. note, default in dev environment cache disabled.

check this blog entry more detailed info


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -