Skip to content

Caching Policy

Overview

The Yappes Caching Policy allows you to improve API performance by storing frequently accessed responses at the gateway level, so you can reduce backend load and deliver faster response times to your users.

This powerful feature enables you to configure caching rules based on various parameters such as headers, paths, and query parameters, ensuring that your APIs serve cached content when appropriate while maintaining data freshness through configurable expiry times.

The caching feature integrates seamlessly into the Yappes API management workflow, offering flexible implementation options that adapt to your needs. Whether you're onboarding a new API or optimizing existing ones, caching policies help you achieve significant performance improvements with minimal configuration effort.

By implementing caching at the gateway level, you gain centralized control over cache management, reduce infrastructure costs, and enhance the overall user experience through faster API responses.

Prerequisites

Before implementing Caching on the Yappes platform, ensure you have:

Access Requirements:

  • Valid Yappes platform account with API Manager access
  • Appropriate permissions to create and manage gateway policies
  • Rights to onboard and configure APIs

Preliminary Setup:

  • At least one API ready for onboarding (if using the onboarding method)

Estimated Time:

  • 15-20 minutes for initial setup

Custom error and message

For error scenarios, you can override the default HTTP status code, error code, and message. See Custom Error and Message.


Step-by-Step Implementation

Important: Caching policies can be created using two methods. Choose the approach that best fits your workflow.

Method 1: Creating Caching During API Onboarding

Step 1: Navigate to API Management

  1. Click on Manage APIs in the main dashboard.
  2. Select My APIs from the submenu.
  3. You should now see your API management interface.

Accessing Create Policy Options

Step 2: Initiate API Onboarding

  1. Follow onboarding steps

Step 3: Select Endpoint for Caching

  1. Click on your newly created endpoint (e.g., "Get Post Data").
  2. The endpoint details panel will open.

Select Endpoint for Caching

Step 4: Access Caching Configuration

  1. Locate and click the Caching button in the interface.
  2. Click on Create Caching to open the policy configuration panel.
  3. The caching configuration interface will display.

Access Caching Configuration

Step 5: Create the Caching Policy

  1. Enter a descriptive name in the Policy Name* field (e.g., Post Cache Region policy).
  2. Add a detailed description in the Enter description field to document the policy purpose.
  3. Set Cache Expiry* to determines how long responses remain cached (e.g., 50).

Create the Caching Policy

Step 6: Define Cache Parameters

  1. In the Parameter* dropdown, select your cache key type:
  2. Header: Cache based on request headers
  3. Path: Cache based on URL path
  4. Query Parameter: Cache based on query strings
  5. Enter the Key* (e.g., browser).
  6. Enter the Value* (e.g., chrome).
  7. Click Add Match Rule to add another parameter.

Define Cache Parameters

Step 7: Finalize Caching Policy

  1. Review your caching configuration.
  2. Click on Create policy to save, attach and activate the caching policy.

Finalize Caching Policy

Method 2: Creating Caching from Gateway Policy Page

Step 1: Navigate to Gateway Policies

  1. Locate Gateway Control -> Gateway Policies in the main navigation menu.
  2. The policies management interface will display.

Navigate to Gateway Policies

Step 2: Initialize New Policy Creation

  1. Click on Create Policy button.
  2. The policy creation dialog will open.

New Policy Creation

Step 3: Configure Policy Settings

  1. Set the Control Level to API Level.
  2. In the Policy Type dropdown, select Caching.
  3. These settings determine the policy scope and functionality.

Configure Policy Settings

Step 4: Define Policy Details

  1. Enter a descriptive name in the Policy Name* field (e.g., Post cache Region policy).
  2. Add a detailed description in the Description field to document the policy purpose.
  3. Set Cache Expiry* to determines how long responses remain cache0d. (e.g., 50).
  4. Select the target API and the Endpoint from the respective dropdown list.
  5. Set Cache Expiry Time in seconds (e.g., 50)

Policy Details

Step 5: Define Caching Parameters

  1. In the Parameter* dropdown, select your cache key type:
  2. Header: Cache based on request headers
  3. Path: Cache based on URL path
  4. Query Parameter: Cache based on query strings
  5. Enter the Key* (e.g., browser).
  6. Enter the Value* (e.g., chrome).
  7. Click Add Match Rule to add another parameter.

Caching Parameters

Step 6: Create and Activate Policy

  1. Review all settings carefully.
  2. Click Create policy to finalize.
  3. The policy will be immediately saved, attached and activated for the selected API’s endpoint.

Create and Activate Policy

Invalidate Caching from Edit Policy Page

  1. Open edit cache dialog
  2. Click on invalidate cache to clear the cache from the storage
  3. Will get confirmation of cache invalidated

Invalidate Caching from Edit Policy Page

Understanding the Interface

Caching Policy Interface Overview

The caching policy interface includes several important sections:

Policy Information Panel

  • Policy Name: Unique identifier for your caching policy.
  • Description: Human-readable explanation of the policy purpose.
  • Status Indicator: Shows if the policy is active or inactive.
  • API Association: Displays which API the policy is attached to Configuration Settings Area.
  • Cache Expiry Control: Slider or input field for setting cache duration.
  • Parameter Type Selector: Dropdown for choosing cache key criteria.
  • Match Rules Table: List of all configured cache matching rules.
  • Add Matching Rule Button: Interface for adding new cache parameters.

Configuration and Settings

Core Configuration Options

Setting Description Example Best Practice
Policy Name Unique identifier for the caching policy user-data-cache Use descriptive names indicating cached content
Description Detailed explanation of policy purpose "Caches user profile data for 60 seconds" Include cache duration and data type
Cache Expiry (Sec) Duration before cache invalidation 50 Balance freshness with performance needs
Control Level Scope of policy application API Level Use API Level for targeted caching
Policy Type Type of gateway policy Caching Always set to Caching for cache policies

Parameter Configuration

Available Parameter Types:

  1. Header Parameters

  2. Use for: User-agent specific caching, authentication tokens.

  3. Example: Cache different responses for mobile vs desktop browsers.
  4. Key: User-Agent, Value: Mobile.

  5. Path Parameters

  6. Use for: Resource-specific caching.

  7. Example: Cache individual user profiles.
  8. Pattern: /users/{id}/*.

  9. Query Parameters

  10. Use for: Search result caching, filtered data.
  11. Example: Cache search results by query.
  12. Key: search, Value: products.

Cache Expiry Guidelines

Best Practice: Set expiry times based on data volatility

  • Static Content (images, documents): 3600–86400 seconds.
  • User Profiles: 300–600 seconds.
  • Product Catalogs: 600–1800 seconds.
  • Real-time Data: 10–60 seconds.
  • Analytics Data: 300–900 seconds.

Verification and Testing

Step 1: Initial Cache Test

  • Send a request to your cached endpoint
  • Note the response time (first request fetches from backend)
  • Send an identical request immediately
  • Compare response times - cached response should be significantly faster

Step 2: Verify Cache Headers

  • Inspect response headers for cache indicators:
  • Look for X-Cache: HIT for cached responses
  • Check for X-Cache: MISS on first requests
  • Verify Cache-Control headers match your configuration

Step 3: Parameter-Based Testing

  • Send requests with different parameter values
  • Verify that only matching parameters return cached responses
  • Test each configured match rule independently

Step 4: Expiry Validation

  • Make a request and note the time
  • Wait for cache expiry duration plus 5 seconds
  • Repeat the request—it should fetch fresh data
  • Subsequent requests should be cached again

Step 5: Backend Monitoring

  • Check backend logs for reduced request volume
  • Monitor API metrics for improved response times
  • Verify cache hit ratio in gateway analytics

Troubleshooting

Common Issues and Solutions

Cache Not Working (All Requests Hit Backend)

  • ✓ Verify policy is attached to correct API.
  • ✓ Check that parameter values match exactly.
  • ✓ Ensure cache expiry time is greater than 0.
  • ✓ Confirm policy status shows as "Active".

Stale Data Being Served

  • ✓ Review cache expiry settings—may be too long.
  • ✓ Check if cache invalidation is working.
  • ✓ Verify backend is returning updated data.
  • ✓ Consider implementing cache purge for critical updates

Inconsistent Cache Behavior

  • ✓ Check for multiple conflicting cache policies.
  • ✓ Verify parameter matching rules are specific enough.
  • ✓ Review gateway logs for policy execution errors.
  • ✓ Test with simplified match rules first

Performance Not Improving

  • ✓ Confirm cache hit ratio is above 50%.
  • ✓ Check that frequently accessed endpoints are cached.
  • ✓ Verify cache key parameters are appropriate.
  • ✓ Consider increasing cache expiry for stable data

Error Messages

Error Cause Solution
"Policy creation failed" Invalid configuration Review all required fields
"Cache expiry invalid" Non-numeric or negative value Enter positive integer for seconds
"Parameter conflict" Duplicate match rules Remove duplicate rules
"API not found" Invalid API selection Refresh and select valid API

Pro Tip

Begin with caching on read-heavy endpoints with predictable access patterns. This provides immediate performance benefits while you learn optimal cache configurations for your specific use cases.