# addAttribute() und generateAttributeModels() und der cache..

**URL:** <https://forum.shopware.com/t/addattribute-und-generateattributemodels-und-der-cache/9679>\
**Category:** Shopware 3.5\
**Tags:** programming\
**Created:** [7. November 2012 um 20:04 UTC](https://forum.shopware.com/t/addattribute-und-generateattributemodels-und-der-cache/9679 "2012-11-07T20:04:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bui\_ak](https://avatars.discourse-cdn.com/v4/letter/b/c37758/32.png) [@bui\_ak](https://forum.shopware.com/u/bui_ak)\
**Post date:** [7. November 2012 um 20:04 UTC](https://forum.shopware.com/t/addattribute-und-generateattributemodels-und-der-cache/9679/1 "2012-11-07T20:04:41Z")

</div>

hallo, es hiess ja, daß addAttribute() erst ab 4.0.4 zuverlässig läuft [http://jira.shopware.de/Widgets/Jira/?ticket=SW-4077](http://jira.shopware.de/Widgets/Jira/?ticket=SW-4077) folgendes kleine plugin bereitet uns große sorgen: [code]\<?php class Shopware\_Plugins\_Backend\_SwpAttributeCache\_Bootstrap extends Shopware\_Components\_Plugin\_Bootstrap {  
protected $name = ‚AttributeCache‘;

public function install() {  
Shopware()-\>Models()-\>addAttribute(‚s\_articles\_attributes‘, ‚swp\_attribute\_cache‘, ‚id‘, ‚INT(11)‘, true, ‚0‘); Shopware()-\>Models()-\>addAttribute(‚s\_articles\_attributes‘, ‚swp\_attribute\_cache‘, ‚container\_id‘, ‚INT(11)‘, true, ‚0‘); Shopware()-\>Models()-\>addAttribute(‚s\_categories\_attributes‘, ‚swp\_attribute\_cache‘, ‚id‘, ‚INT(11)‘, true, ‚0‘); Shopware()-\>Models()-\>addAttribute(‚s\_order\_attributes‘, ‚swp\_attribute\_cache‘, ‚id‘, ‚INT(11)‘, true, ‚0‘); Shopware()-\>Models()-\>addAttribute(‚s\_user\_attributes‘, ‚swp\_attribute\_cache‘, ‚id‘, ‚INT(11)‘, true, ‚0‘); $metaDataCache = Shopware()-\>Models()-\>getConfiguration()-\>getMetadataCacheImpl(); $metaDataCache-\>deleteAll(); $this-\>Application()-\>Models()-\>generateAttributeModels(array(‚s\_articles\_attributes‘)); $this-\>Application()-\>Models()-\>generateAttributeModels(array(‚s\_categories\_attributes‘)); $this-\>Application()-\>Models()-\>generateAttributeModels(array(‚s\_order\_attributes‘)); $this-\>Application()-\>Models()-\>generateAttributeModels(array(‚s\_user\_attributes‘)); return parent::install(); } public function uninstall() { Shopware()-\>Models()-\>removeAttribute(‚s\_articles\_attributes‘, ‚swp\_attribute\_cache‘, ‚id‘); Shopware()-\>Models()-\>removeAttribute(‚s\_articles\_attributes‘, ‚swp\_attribute\_cache‘, ‚container\_id‘); Shopware()-\>Models()-\>removeAttribute(‚s\_categories\_attributes‘, ‚swp\_attribute\_cache‘, ‚id‘); Shopware()-\>Models()-\>removeAttribute(‚s\_order\_attributes‘, ‚swp\_attribute\_cache‘, ‚id‘); Shopware()-\>Models()-\>removeAttribute(‚s\_user\_attributes‘, ‚swp\_attribute\_cache‘, ‚id‘); $metaDataCache = Shopware()-\>Models()-\>getConfiguration()-\>getMetadataCacheImpl(); $metaDataCache-\>deleteAll(); $this-\>Application()-\>Models()-\>generateAttributeModels(array(‚s\_articles\_attributes‘)); $this-\>Application()-\>Models()-\>generateAttributeModels(array(‚s\_categories\_attributes‘)); $this-\>Application()-\>Models()-\>generateAttributeModels(array(‚s\_order\_attributes‘)); $this-\>Application()-\>Models()-\>generateAttributeModels(array(‚s\_user\_attributes‘)); return parent::uninstall(); } public function enable() { return true; } public function disable() { return true; } public function getVersion() { return ‚4.0.0‘; } } [/code] beim versuch dieses auf einem macbook-pro zu installieren gibts einen ajax-timeout seitens ext-js. auf einem etwas performanteren pc mit SSD-systemplatte dauert die installation auch ein paar sekunden, aber es gibt keinen timeout. zur erläuterung des problems hier die vorgehensweise. 4.0.4 neu aufsetzen, 4.0.4 demodaten einspielen. per rm -fr ./cache/database/\* den datenbank cache löschen. ein reload auf das backend liefert dann: ` # du -h ./cache/database/ 3,1M ./cache/database/shopware--Shopware/shopware--Models/shopware--6174 3,0M ./cache/database/shopware--Shopware/shopware--Models 20K ./cache/database/shopware--Shopware/shopware--Config/shopware--300 28K ./cache/database/shopware--Shopware/shopware--Config 3,1M ./cache/database/shopware--Shopware 3,1M ./cache/database/ ` nach dem laden des pluginmanagers: 3.5M. nach installation von AttributeCache: 47M dabei werden unglaubliche 11483 dateien erzeugt: ` # ls -l ./cache/database/shopware--Shopware/shopware--Models/shopware--6174/ | wc -l 11483 ` die große überraschung kommt aber nach neuinstallation des plugins: nach dem uninstall verdoppeln sich in etwa die dateien im cache ` # du -h ./cache/database/90M ./cache/database/shopware--Shopware/shopware--Models/shopware--6174 90M ./cache/database/shopware--Shopware/shopware--Models 24K ./cache/database/shopware--Shopware/shopware--Config/shopware--300 28K ./cache/database/shopware--Shopware/shopware--Config 90M ./cache/database/shopware--Shopware 90M ./cache/database/ ` und erneutem install: ` du -h ./cache/database/ 134M ./cache/database/shopware--Shopware/shopware--Models/shopware--6174 134M ./cache/database/shopware--Shopware/shopware--Models 24K ./cache/database/shopware--Shopware/shopware--Config/shopware--300 28K ./cache/database/shopware--Shopware/shopware--Config 134M ./cache/database/shopware--Shopware 134M ./cache/database/ ` was machen wir falsch?

---

<div class="post-metadata">

**Author:** ![Benjamin\_Cremer](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@Benjamin\_Cremer](https://forum.shopware.com/u/Benjamin_Cremer)\
**Post date:** [8. November 2012 um 08:43 UTC](https://forum.shopware.com/t/addattribute-und-generateattributemodels-und-der-cache/9679/2 "2012-11-08T08:43:15Z")

</div>

Hallo, das manuelle leeren des metaDataCaches ist ab Version 4.0.4 nicht mehr nötig. Des Weiteren solltest du die Aufrufe von generateAttributeModels zusammenfassen. Statt: ` $this-\>Application()-\>Models()-\>generateAttributeModels(array('s\_articles\_attributes')); $this-\>Application()-\>Models()-\>generateAttributeModels(array('s\_categories\_attributes')); $this-\>Application()-\>Models()-\>generateAttributeModels(array('s\_order\_attributes')); $this-\>Application()-\>Models()-\>generateAttributeModels(array('s\_user\_attributes')); ` Besser: ` $this-\>Application()-\>Models()-\>generateAttributeModels(array( 's\_articles\_attributes', 's\_categories\_attributes', 's\_order\_attributes', 's\_user\_attributes', )); ` Durch diese beiden Änderungen wird der metaDataCache nicht 5 mal, sondern nur ein einziges mal geleert. Viele Grüße Benjamin Cremer :shopware:

---

<div class="post-metadata">

**Author:** ![bui\_ak](https://avatars.discourse-cdn.com/v4/letter/b/c37758/32.png) [@bui\_ak](https://forum.shopware.com/u/bui_ak)\
**Post date:** [8. November 2012 um 19:37 UTC](https://forum.shopware.com/t/addattribute-und-generateattributemodels-und-der-cache/9679/3 "2012-11-08T19:37:33Z")

</div>

das weglassen von metaDataCache-\\>deleteAll(); und zusammenfassung der tabellennamen bei generateAttributeModels() ändert leider nichts an der laufzeit und der generierung von ca. 43.5 MB cachefiles [b]pro[/b] installation/deinstallation des plugins... das stimmt doch irgendwas nicht. die textuelle repräsentation der kompletten sw4+demodaten ist lediglich 1.8M groß... [code] mysqldump -uroot shopware\_4 \> dmp $ ls -lh dmp -rw-rw-r-- 1 ak ak 1,8M Nov 8 19:38 dmp [/code]

---

<div class="post-metadata">

**Author:** ![Benjamin\_Cremer](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@Benjamin\_Cremer](https://forum.shopware.com/u/Benjamin_Cremer)\
**Post date:** [9. November 2012 um 11:11 UTC](https://forum.shopware.com/t/addattribute-und-generateattributemodels-und-der-cache/9679/4 "2012-11-09T11:11:42Z")

</div>

Hallo, der metaDataCache cached keine Daten aus der DB. Der metaDataCache kümmert sich um das Caching der Anotationen der Doctrine-Models. Beispiel: ` /\*\* \* @var \Doctrine\Common\Collections\ArrayCollection \* @ORM\ManyToMany(targetEntity="Shopware\Models\Customer\Group") \* @ORM\JoinTable(name="s\_articles\_avoid\_customergroups", \* joinColumns={ \* @ORM\JoinColumn(name="articleID", referencedColumnName="id") \* }, \* inverseJoinColumns={ \* @ORM\JoinColumn(name="customergroupID", referencedColumnName="id", unique=true) \* } \* ) \*/ protected $customerGroups; ` Die Anotationen die mit @ORM anfangen werden hier gecached. Mit der Version 4.0.5 wird es möglich sein, APC als metaDataCache zu konfigurieren. Dies wird die Geschwindigkeit nochmal deutlich erhöhen. Zum Testen kannst du folgende Methode in der /engine/Shopware/Components/Model/Configuration.php ersetzen: ` public function setCacheResource($cacheResource) { if (extension\_loaded('apc') && ini\_get('apc.enabled')) { $cache = new \Doctrine\Common\Cache\ApcCache(); } elseif (PHP\_OS === 'WINNT') { $cache = new \Doctrine\Common\Cache\ArrayCache(); } else { $cache = new \Shopware\Components\Model\Cache($cacheResource); } $this-\>setMetadataCacheImpl($cache); $this-\>setQueryCacheImpl($cache); } ` Nun wird der metaDataCache, bei aktivierten APC nicht mehr in das Dateisystem geschrieben. Achtung: Dies ist nicht der Finale Code der 4.0.5 Version. Viele Grüße, Benjamin Cremer :shopware:

---

<div class="post-metadata">

**Author:** ![bui-aa](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@bui-aa](https://forum.shopware.com/u/bui-aa)\
**Post date:** [9. November 2012 um 13:20 UTC](https://forum.shopware.com/t/addattribute-und-generateattributemodels-und-der-cache/9679/5 "2012-11-09T13:20:09Z")

</div>

Hallo, mit dem APC-Cache funktioniert es nun wunderbar. Nun kann selbst ich, ohne SSD, das Plugin installieren. 🙂
