Prevent Magento from caching query strings, such as limit param

Prevent Magento from caching query strings, such as limit param

September 2, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Prevent Magento from caching query strings, such as limit param

Preventing Magento from Caching Query Strings: Understanding the Behavior

Dear developers,

Today we’re going to tackle an interesting issue related to Magento’s caching behavior that often confuses developers. Let’s dive into understanding why Magento might be caching your query string parameters and how you can prevent it from doing so.

The Behavior Explained

You’ve set up your category listing to display only 3 products per page using the catalog.xml configuration:

<action method="setDefaultGridPerPage"><limit>3</limit></action>
<action method="addPagerLimit"><mode>grid</mode><limit>3</limit></action>

When you navigate to /category.html, it displays only 3 products perfectly. You’re happy with this behavior.

However, your requirements have evolved. Now, you also want the option to display all products at once by using a query string parameter:

<action method="addPagerLimit"><mode>grid</mode><limit>999</limit></action>

When you navigate to /category.html?limit=999, it shows all the category’s products without any issue.

The Problem: Magento Caches Listing Options

The problem arises when you return to the default listing at /category.html with no limit parameters. Despite your configuration, Magento displays all the products instead of the 3 you intended. This is because Magento caches the limit preference for future requests.

The Question: Preventing Magento from Caching Query Strings

You’re wondering if there’s a way to configure Magento to prevent it from caching listing options like in our case:

Is there a configuration that prevents magento from caching listing options?

The Solution: Clearing Cache at Runtime

The key here is to understand that Magento uses the Mage_Core_Model_Config class for handling configurations. It stores its cache in the core_config_data table, which is where you need to focus your attention.

To prevent Magento from caching certain parameters, you can use the addActionCacheKey() method while setting up your configuration:

<action method="setDefaultGridPerPage">
    <limit>3</limit>
    <addActionCacheKey>true</addActionCacheKey>
</action>

This tells Magento not to cache this specific configuration for future requests.

Remember, this is a global solution that should be used sparingly and only when necessary. It’s important to ensure you’re not negatively impacting performance by clearing the cache too frequently.

Conclusion

Understanding how Magento handles caching is crucial for optimizing your store’s performance and user experience. By learning about the addActionCacheKey method, you can now customize Magento’s behavior to better suit your specific requirements without compromising on speed or efficiency.

At LaravelCompany, we’re always eager to share more insights into Magento development best practices. If you have any other questions related to Magento configuration or caching strategies, feel free to reach out!

Stay tuned for our next technical post, where we’ll explore a different aspect of Magento’s core functionalities.

Happy coding!

Catalog Cache Database API

Our network