1cd920a91f48385ae166e32437aec3935bd6f03b
DB Memory Cache for PrestaShop
A high-performance caching module for PrestaShop 8 and 9 that utilizes the MySQL/MariaDB MEMORY (HEAP) engine. This module provides a fast, ephemeral key-value store directly in RAM without requiring external services like Redis or Memcached.
Features
- Speed: Uses the
MEMORYdatabase engine to store data in RAM, avoiding disk I/O. - TTL Support: Simulates Time-To-Live expiration for cached items.
- Unicode Optimized: Uses
JSON_UNESCAPED_UNICODEto save space and support multi-byte characters efficiently. - Safety: Automatically rejects data larger than the defined limit (~16KB) to prevent SQL errors or JSON truncation.
- Strict Logic: Ensures clean writes by deleting existing keys before insertion.
Requirements
- PrestaShop 8.0.0 or higher (Compatible with PS 9).
- MySQL or MariaDB.
- The database user must have
CREATEandDROPprivileges (standard for PS).
Installation
- Create a folder named
dbmemorycachein your PrestaShopmodules/directory. - Upload
dbmemorycache.phpandlogo.png(optional) to that folder. - Go to Back Office > Modules > Module Manager.
- Search for "MySQL Memory Cache Optimized".
- Click Install.
Technical Limitations
- Volatility: Data stored in
MEMORYtables is lost if the MySQL server restarts. Do not use this for persistent data. - Size Limit: The maximum value size is approximately 16,000 characters (due to
VARCHARlimits in MEMORY tables andutf8mb4encoding). If you attempt to cache data larger than this, theset()method will returnfalseand the data will not be cached.
Usage Examples
You can call this module from any other module, controller, or hook in PrestaShop.
1. Basic Usage (Get & Set)
// 1. Get the module instance
$cache = Module::getInstanceByName('dbmemorycache');
// Ensure module is installed and active
if ($cache && Module::isInstalled('dbmemorycache')) {
$key = 'my_custom_api_data_v1';
// 2. Check if data exists and is valid (not expired)
if ($cache->existsValue($key)) {
$data = $cache->getValue($key);
// $data is now your array/object
} else {
// 3. Fetch your expensive data
$data = [
'id' => 123,
'name' => 'Product Name',
'features' => ['A', 'B', 'C']
];
// 4. Store in cache for 1 hour (3600 seconds)
// Returns true on success, false if data is too big
$cache->setValue($key, $data, 3600);
}
}
Description
Languages
PHP
82.8%
Smarty
17.2%