Skip to main content

Deploy a Cache

Now that you have both a web application and database running, it's time to add high-performance caching using Viduli's Flash Cache Service. Flash provides managed Redis clusters that can dramatically improve your application's response times by caching frequently accessed data in memory, reducing database load and enhancing user experience.

In this tutorial, you'll deploy a Redis cache cluster and connect it to your existing FastAPI application and PostgreSQL database. You'll see how Viduli automatically handles cache configuration and makes connection details available to your applications. For comprehensive information about Flash's capabilities, see the complete Flash documentation.

Prerequisites

Before deploying your cache, ensure you have:

  • A Viduli project with a web application and database: Complete the Deploy a Database tutorial first
  • Basic understanding of caching: Helpful for understanding performance benefits
  • Familiarity with Redis: Not required, but useful for advanced configurations

Cache Overview

For this tutorial, we'll deploy a Redis cache cluster that will store frequently accessed data for your FastAPI application. Redis is an excellent choice for web application caching because it provides:

  • Ultra-fast performance: Microsecond latency with in-memory storage
  • Rich data types: Strings, hashes, lists, sets, and more
  • Atomic operations: Ensures data consistency
  • Pub/Sub messaging: Real-time communication capabilities
  • High throughput: Handles millions of requests per second

Your cache will be automatically configured with secure connections and monitoring - everything you need for a production-ready caching layer.

Step-by-Step Instructions

1. Access Your Project

Navigate to your project by clicking on the project name in the sidebar. You should see your FastAPI application and PostgreSQL database from the previous tutorials already deployed on the canvas.

2. Start Cache Creation

In the project overview, click the New Resource button in the sidebar. This opens the resource creation dialog where you can choose from different types of resources.

3. Select Flash Cache Service

From the resource type options, select Flash to create a new managed cache. This will open the Flash cache configuration form.

4. Choose Redis Engine

Since we're building a high-performance caching layer for our web application, select Redis as your cache engine. Redis is ideal for web application caching due to its speed, flexibility, and rich feature set.

5. Configure Cache Version

In the Cache Configuration section, select your Redis version:

  • Version: Select 7.2.7 from the version dropdown

Redis 7.2.7 provides excellent performance and stability with the latest caching features and security enhancements.

6. Configure Compute Resources

In the Compute section, set appropriate resources for your cache:

  • CPU: Select 125m (125 millicpu = 12.5% of a CPU core)
  • Memory: Select 128mb RAM
  • Disk: Select 20GB storage

These minimal resources are perfect for development and testing workloads, providing sufficient cache capacity while keeping costs low.

7. Configure Scaling

In the Scaling section, configure your cache deployment:

  • Region Mode: Select Single Region
  • Region: Choose US East (or match the region of your other resources)
  • Replication: Set to Standalone for this tutorial

Keeping your cache, database, and application in the same region minimizes latency and maximizes performance. Standalone mode provides a single Redis instance without replication, which is sufficient for development and testing.

tip

For production workloads, consider Active-Passive or Cluster replication modes for high availability and improved performance.

8. Configure Cache Identity

In the General section, set up your cache identity:

  • Label: Enter Tags Store (this is the display name)
  • Name: This will automatically populate as tags-store based on the label

Choose a descriptive name that makes it easy to identify this cache's purpose within your project.

9. Review Cost Estimates

Before creating your cache, review the total estimated cost displayed in the interface. Viduli shows a single combined monthly price that includes the compute resources and storage costs.

10. Deploy Your Cache

Click the Create button to deploy your cache. Viduli will now:

  • Provision Redis infrastructure
  • Configure networking and security
  • Initialize the Redis cluster
  • Generate connection credentials

Monitor Cache Deployment

After clicking Create, your cache will appear on the project canvas:

  1. Select the cache if it's not already selected
  2. Check the status in the right sidebar - it should show Launching
  3. Wait for completion - cache deployment typically takes under a minute
  4. Verify success - the status will change to Healthy when ready

Cache provisioning is typically faster than database deployment because Redis clusters are designed for rapid startup and immediate availability.

Automatic Environment Variable Export

Once your cache is running, Viduli automatically exports connection details as environment variables to your project. These variables become available to all resources in the same project:

  • TAGS_STORE_HOST: Cache server hostname
  • TAGS_STORE_PORT: Cache port (typically 6379)
  • TAGS_STORE_URL: Complete connection string

Update Your Web Application

To make your FastAPI application use the new cache:

1. Redeploy Your Application

Since environment variables are only updated when resources are deployed:

  1. Select your FastAPI application on the canvas
  2. Click the deploy button in the application controls
  3. Wait for redeployment to complete

This ensures your application receives the new cache environment variables.

2. Verify Cache Connection

Your application can now access the cache using the automatically provided environment variables. In your FastAPI code, you would typically use:

import os
import redis

cache_url = os.getenv('TAGS_STORE_URL')
cache_client = redis.from_url(cache_url)

Test Cache Connectivity

Once both your application and cache are running, you can verify the connection:

1. Check Application Logs

  1. Select your FastAPI application on the canvas
  2. Open the resource details by double-clicking or using the sidebar
  3. Navigate to the Logs tab to see connection status
  4. Look for cache connection messages in the application startup logs

2. Test Cache Operations

Test the cache connectivity by hitting the health check endpoint of your API, which verifies the cache connection:

# Test cache connectivity via API health check
curl https://organization-team-project.viduli.app/api/articles/health

Cache Management

Access Cache Shell

You can connect directly to your cache for administration and debugging:

  1. Select your cache on the canvas
  2. Open the resource details view
  3. Navigate to the Shell tab
  4. Use the redis-cli interface for direct cache access

Monitor Cache Performance

Track your cache performance through the monitoring interface:

  1. Open the cache details view
  2. Navigate to the Monitoring tab
  3. Review metrics like memory usage, hit rates, and request throughput
info

Always Running: Redis cache clusters run continuously and do not support start/stop operations. This ensures optimal cache performance and data availability at all times.

What You've Accomplished

Congratulations! You've successfully deployed a production-ready Redis cache cluster. Your cache now provides:

  • Ultra-Fast Performance: Microsecond response times for cached data
  • Managed Infrastructure: No server maintenance or configuration required
  • Security: Encrypted connections and isolated networking
  • Seamless Integration: Automatic environment variable provisioning
  • Cost Efficiency: Pay only for the resources you use

Next Steps

Now that you have a complete application stack (web app, database, and cache), you can:

  • Implement Caching Logic: Add cache operations to your FastAPI application
  • Optimize Performance: Use cache for session storage, API responses, and database query results
  • Monitor Usage: Track cache hit rates and performance metrics
  • Scale Resources: Adjust CPU, memory, or upgrade to clustered replication as needed
  • Add Custom Domains: Configure your own domain names for the application