Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/JuanSCaicedo/Api-Ecommerce/llms.txt

Use this file to discover all available pages before exploring further.

API Ecommerce uses Laravel’s Cache facade to cache the responses of read-heavy storefront endpoints. By wrapping expensive database queries inside Cache::remember(), repeated requests for the same data are served directly from the cache store without hitting MySQL. The default cache driver is file (responses are stored as serialised files on disk), but Redis is strongly recommended for any non-trivial deployment.
Switch to the Redis cache driver in production. File-based caching works for a single-server setup but does not scale to multiple application instances and performs poorly under high concurrency. See Configuring the cache driver below.

Cached endpoints

The following TTL constants are defined in HomeController:
private const CACHE_DURATION       = 2592000; // 30 days  (seconds)
private const CACHE_DURATION_DAILY = 86400;   // 24 hours (seconds)
EndpointCache keyTTLNotes
GET /api/ecommerce/homehome_response_{Y-m-d_H}2592000 s (30 days)Key rotates every hour; a new key is generated at the start of each clock hour, causing the first request of each hour to rebuild the cache
GET /api/ecommerce/menumenu_response_{Y-m-d}86400 s (24 hours)Key rotates daily at midnight
GET /api/ecommerce/product/{slug}product_{slug}_{campaing}2592000 s (30 days){campaing} is the value of the campaing_discount query parameter, or no_discount if omitted
Flash discount productsdiscount_flash_products2592000 s (30 days)Collection of products belonging to the active type-2 flash discount campaign
Discount flash campaigndiscount_flash2592000 s (30 days)The active flash discount model itself
Principal sliderssliders_principal2592000 s (30 days)type_slider = 1
Secondary sliderssliders_secundario2592000 s (30 days)type_slider = 2
Product sliderssliders_products2592000 s (30 days)type_slider = 3
Random categories (home)categories_randoms2592000 s (30 days)5 randomly selected active top-level categories
Menu categoriesmenu_categories86400 s (24 hours)Nested category tree used by the storefront navigation
Product sections (trending, featured, etc.)products_{section}2592000 s (30 days)One key per section: products_trending_new, products_trending_featured, products_trending_top_sellers, products_last_discounts, products_last_featured, products_last_selling, electronics, carusel
Related productsrelated_products_{product_id}2592000 s (30 days)Cached per product
Maintenance statusmaintenance_status300 s (5 minutes)Boolean — whether vista_mantenimiento is active. Short TTL so maintenance mode changes propagate within 5 minutes
The home and show_product endpoints wrap the entire response object — including nested collections — in a single Cache::remember() call:
// HomeController::home — key rotates every hour
$cacheKey = 'home_response_' . now()->format('Y-m-d_H');

return Cache::remember($cacheKey, self::CACHE_DURATION, function () {
    if ($this->isUnderMaintenance()) {
        return response()->json(["message" => "El sitio está en mantenimiento"], 503);
    }
    // ... build and return the full home response
});

// HomeController::show_product
$cacheKey = "product_{$slug}_" . ($request->get("campaing_discount") ?? 'no_discount');

return Cache::remember($cacheKey, self::CACHE_DURATION, function () use ($request, $slug) {
    // ... build and return the full product detail response
});
The maintenance status itself is cached for 300 seconds (5 minutes) to avoid a database query on every single request:
private function isUnderMaintenance()
{
    return Cache::remember('maintenance_status', 300, function () {
        return HomeView::where("name", "vista_mantenimiento")
                       ->where("state", 1)
                       ->exists();
    });
}

Cache invalidation

API Ecommerce uses a flush-on-write strategy: every admin or storefront write operation that could affect cached storefront data calls Cache::flush() to clear the entire cache store. This guarantees consistency at the cost of a cold cache after each write.
Cache::flush() removes all keys from the configured cache store — not just the keys belonging to this application. If you share a Redis instance with other applications, or run API Ecommerce in a multi-tenant environment, use Laravel tagged cache to scope invalidation to only this application’s keys.
Cache::flush() is called inline in admin controllers after each write, and via the clearAllProductCaches() private helper in SaleController, ReviewController, and AuthController:
// Called inline in Admin\Product\ProductController after store/update/destroy/delete_imagen
Cache::flush();

// Used in SaleController, ReviewController, and AuthController::update
private function clearAllProductCaches()
{
    Cache::flush(); // Clears all cache keys
}
The following write operations trigger cache invalidation:
OperationControllerInvalidation method
Product createAdmin\Product\ProductController::storeCache::flush()
Product updateAdmin\Product\ProductController::updateCache::flush()
Product deleteAdmin\Product\ProductController::destroyCache::flush()
Product image deleteAdmin\Product\ProductController::delete_imagenCache::flush()
Slider create / update / deleteAdmin\SliderControllerCache::flush()
Discount create / update / deleteAdmin\Discount\DiscountControllerCache::flush()
Coupon create / updateAdmin\Cupone\CuponeController::store, ::updateCache::flush()
Home view updateAdmin\HomeViewController::updateCache::flush()
User profile updateAuthController::updateCache::flush() via clearAllProductCaches()
Review create / updateEcommerce\ReviewControllerCache::flush() via clearAllProductCaches()
Checkout (direct payment)Ecommerce\SaleController::storeCache::flush() via clearAllProductCaches()
Checkout (MercadoPago)Ecommerce\SaleController::checkout_mercadopagoCache::flush() via clearAllProductCaches()
CuponeController::destroy does not call Cache::flush(). Deleting a coupon will not invalidate cached storefront responses that may reference the deleted coupon. HomeViewController::store and HomeViewController::destroy are currently unimplemented stubs and do not flush the cache either.

Configuring the cache driver

By default Laravel uses the file driver. Add the following variables to your .env file to switch to Redis:
CACHE_DRIVER=redis
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=null
REDIS_DB=0
Ensure the predis/predis or phpredis extension is installed before switching drivers. After changing the driver, run:
php artisan cache:clear
to remove any stale file-based cache entries.

Build docs developers (and LLMs) love