How to temporarily turn off cache
- Morfeo21
- Member | 35
Hi!
I'd like to ask how can I temporarily turn off a cache for a special
script – XML import in concrete.
I have XML import which uses repositories' methods for insert and update of
products. These methods contains some required funcionalities. One of them is
invalidating cache. It's required bnecasuse these methods are used in
administration as well for update of single products.
But when I'm importing about 10 000 products the application starts to fall
down on lack of memory. In case of the import I'd like to turn off the cache
(set storage to DevNullStorage
). But I realized that
Cache
class has no method setStorage()
except he
constructor.
Is there a way I can turn off the cache for the special script? From config.neon, on the beginnig of the import … I don't care, I just need the way how to do it :))
Thanks! :)
- Morfeo21
- Member | 35
This is not what I need. I don't want to invalidate whole cache. I just want to switch cache storages.
I sorted it out with these lines:
$container->removeService('cache');
$container->addService('cache', new Nette\Caching\Cache(new Nette\Caching\Storages\DevNullStorage()));
Do you guys have any other solution?
Last edited by Morfeo21 (2014-03-24 10:47)
- Vojtěch Dobeš
- Gold Partner | 1316
I ussualy instantiate Cache
class in my own classes, I don't
register it as service. So maybe this approach could give you desired
flexibility without hacking DI container like this. I have only
Caching\IStorage
as service.