Skip to content

setCache(key, value, ttl=0) Function Documentation

Overview

The setCache(key, value, ttl=0) function is a crucial utility used across Merciglobal Cloud ERP for optimizing performance by temporarily storing data in cache memory. This method helps reduce redundant processing and repeated database hits.

Purpose

This function sets a key-value pair into the cache system with an optional TTL (Time-To-Live) parameter.

Parameters

Parameter Type Required Description
key String ✅ Yes Unique identifier for the cached data.
value Any ✅ Yes The data or object to be stored in the cache.
ttl Integer ❌ No Time in seconds before the cache expires. 0 means it will never expire.

Usage Examples

# Set a user object into cache for 300 seconds
setCache('user_102', {'name': 'Alice', 'role': 'Admin'}, 300)

# Set a config value in cache indefinitely
setCache('site_mode', 'production')

Return Value

  • ✅ Returns True if the data was successfully cached.
  • ❌ Returns False if an error occurred.

Key Notes

  • This function is used heavily in:
  • Session handling
  • API response caching
  • Background task optimizations
  • TTL helps in managing memory by removing stale data.
  • Best practice: Use a unique and descriptive key for each cache entry.

Internal Developer Tips 💡

  • Wrap this function with a try-except block when the value is generated via expensive computation.
  • Use a standard prefix like "module_name:" to avoid key collisions in shared environments.

Sales Insight

Merciglobal Cloud ERP leverages caching across multiple modules including: - Inventory Tracking - Real-time Reporting - User Authorization

⚡ This improves performance and user experience significantly, reducing API response times by up to 70%.

  • getCache(key) – Retrieve a value from the cache.
  • clearCache(key) – Remove a value from the cache.

Stay efficient with smart caching using setCache() in Merciglobal Cloud ERP! ⚙️