Jump to content

Storing The Result Of Getnewproducts Until Products Are Added Or Removed


Recommended Posts

Hi

 

I have a NewProducts module that I am modifying a bit and I noticed that the this operation is a bit slow:

 

$products = Product::getNewProducts((int)Context::getContext()->language->id);

 

So I thought maybe I could just store the result of $products so this query does not have to run for every page load. Then if I could use the actionProductAdd and actionProductDelete to update $products only when needed and Product::getNewProducts would almost never have to run.

 

However this did not work anyway like I thought. Since my module class is instantiated for each page load I can not store anything there. Then I thought about having some flag in "Configuration" but I am not sure if that is a good approach.

 

Can anyone tell me if this is a good idea? Should I even try solving it like this or just rely on whatever caching mechanism is available? Given how rarely we add new products it just seemed a waste to execute this query for each load of the index page.

 

On the other hand, I do not want it to be completely static so I do a shuffle to move the content around a bit like this:

$products = Product::getNewProducts((int)Context::getContext()->language->id);
shuffle($products);
 
so the page does not look the same if the visitor returns and I would like to keep doing that but it would be nice if I did not have to ask for $products from the db always but only occasionally or when new products are added.
 
All suggestions on the proper solution to handle this are warmly welcome

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...