Saturday, August 24, 2013

caching mechanism in opencart

Opencart caches the data at every page load. we have caching on currencies, languages, categories, products, category product counts, weight classes, tax classes, etc.

In front-end models, when fetching data from database, OpenCart looks for the cached data prior to querying the database. They are stored in plain text files using PHP's function serialize(). If system gets any cached data, they are fetched and unserialized and returned to the controller without querying the database.

Thus the fetching should be much quicker. If there are no cached data, then the database is queried and these data are then serialized using PHP's function serialize() and saved to the corresponding cache file.

Here is one small problem that may occur. After You have edited the data directly in the database, (using phpMyAdmin, may the reason be whatever for this) the change is not present at frontend. This is because, there are older data cached that are fetched when asked for them. If You have to do such editing, then do not forget to manually delete corresponding cache file(s).

The cache is instantiated and registered within index.php. it is then accessible in both controllers and models as $this->cache; while methods set(), get() and delete() are callable. The cache class itself could be found at system/library/cache.php and is quite simple and straight forward.

Now, in the administration (backend) part of models, when editing or adding data (category, product, currencies, weight classes, etc), after the data is successfully stored to the database the corresponding cache file is immediately deleted. So it could be re-created at frontend containing up-to-date data.

The cache files could be find at /system/cache/ folder.

See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide

List of my works:

Technical Support:

If you still face the technical problem, please get support of our highly skilled technical team:

Wordpress Plugins:
  1. Real-Time Health Data from Every Where:WP plugin to display real-time health data & increase sale by promoting user specific products according to health information:
  2. Woocommerce Stock Notification Builder:Sends desktop, mobile & email notifications with full customization.Build your own product notification system with it:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

1 comment:

Anonymous said...

Hi there Tahsin, I just read your most interesting post which made me wonder why commercial cache modules performs so much better than OpenCart's native mechanism. Has there been a major change or rollback of OpenCart functions between 2011 and 2014?