Google Antigravity Directory

The #1 directory for Google Antigravity prompts, rules, workflows & MCP servers. Optimized for Gemini 3 agentic development.

Resources

PromptsMCP ServersAntigravity RulesGEMINI.md GuideBest Practices

Company

Submit PromptAntigravityAI.directory

Popular Prompts

Next.js 14 App RouterReact TypeScriptTypeScript AdvancedFastAPI GuideDocker Best Practices

Legal

Privacy PolicyTerms of ServiceContact Us
Featured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver ToolsFeatured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver Tools

© 2026 Antigravity AI Directory. All rights reserved.

The #1 directory for Google Antigravity IDE

This website is not affiliated with, endorsed by, or associated with Google LLC. "Google" and "Gemini" are trademarks of Google LLC.

Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
Caching Strategies Complete

Caching Strategies Complete

Implement effective caching for optimal performance

cachingredisperformancenextjs
by antigravity-team
⭐0Stars
.antigravity
# Caching Strategies Complete Guide for Google Antigravity

Implement effective caching strategies for optimal performance with Google Antigravity IDE.

## Next.js Data Caching

```typescript
// app/products/page.tsx
// Static caching - data cached indefinitely
async function getProducts() {
  const res = await fetch("https://api.example.com/products", {
    cache: "force-cache" // Default behavior
  });
  return res.json();
}

// Time-based revalidation
async function getProductsRevalidated() {
  const res = await fetch("https://api.example.com/products", {
    next: { revalidate: 3600 } // Revalidate every hour
  });
  return res.json();
}

// No caching - always fresh
async function getProductsFresh() {
  const res = await fetch("https://api.example.com/products", {
    cache: "no-store"
  });
  return res.json();
}

// Tag-based revalidation
async function getProduct(id: string) {
  const res = await fetch(`https://api.example.com/products/${id}`, {
    next: { tags: ["products", `product-${id}`] }
  });
  return res.json();
}

// Revalidate by tag
import { revalidateTag } from "next/cache";

export async function updateProduct(id: string, data: ProductData) {
  await db.update(products).set(data).where(eq(products.id, id));
  revalidateTag(`product-${id}`);
  revalidateTag("products");
}
```

## Redis Caching Layer

```typescript
// lib/cache.ts
import { Redis } from "ioredis";

const redis = new Redis(process.env.REDIS_URL!);

interface CacheOptions {
  ttl?: number;
  tags?: string[];
}

export async function cached<T>(
  key: string,
  fn: () => Promise<T>,
  options: CacheOptions = {}
): Promise<T> {
  const { ttl = 3600, tags = [] } = options;

  // Try to get from cache
  const cached = await redis.get(key);
  if (cached) {
    return JSON.parse(cached);
  }

  // Execute function and cache result
  const result = await fn();
  
  await redis.setex(key, ttl, JSON.stringify(result));
  
  // Track tags for invalidation
  for (const tag of tags) {
    await redis.sadd(`tag:${tag}`, key);
  }

  return result;
}

export async function invalidateTag(tag: string): Promise<void> {
  const keys = await redis.smembers(`tag:${tag}`);
  if (keys.length > 0) {
    await redis.del(...keys);
    await redis.del(`tag:${tag}`);
  }
}

// Usage
export async function getUser(id: string) {
  return cached(
    `user:${id}`,
    () => db.query.users.findFirst({ where: eq(users.id, id) }),
    { ttl: 600, tags: ["users", `user:${id}`] }
  );
}
```

## HTTP Caching Headers

```typescript
// app/api/products/route.ts
import { NextResponse } from "next/server";

export async function GET() {
  const products = await getProducts();

  return NextResponse.json(products, {
    headers: {
      "Cache-Control": "public, s-maxage=3600, stale-while-revalidate=86400",
      "CDN-Cache-Control": "max-age=3600",
      "Vercel-CDN-Cache-Control": "max-age=3600"
    }
  });
}

// next.config.ts
export default {
  async headers() {
    return [
      {
        source: "/api/products",
        headers: [
          {
            key: "Cache-Control",
            value: "public, s-maxage=3600, stale-while-revalidate=86400"
          }
        ]
      }
    ];
  }
};
```

## Best Practices

1. **Cache at multiple layers** (CDN, application, database)
2. **Use appropriate TTLs** based on data freshness needs
3. **Implement cache invalidation** with tags
4. **Consider stale-while-revalidate** for better UX
5. **Monitor cache hit rates** in production
6. **Handle cache misses** gracefully
7. **Use consistent cache keys** across the application

Google Antigravity helps implement efficient caching strategies for optimal performance.

When to Use This Prompt

This caching prompt is ideal for developers working on:

  • caching applications requiring modern best practices and optimal performance
  • Projects that need production-ready caching code with proper error handling
  • Teams looking to standardize their caching development workflow
  • Developers wanting to learn industry-standard caching patterns and techniques

By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their caching implementations.

How to Use

  1. Copy the prompt - Click the copy button above to copy the entire prompt to your clipboard
  2. Paste into your AI assistant - Use with Claude, ChatGPT, Cursor, or any AI coding tool
  3. Customize as needed - Adjust the prompt based on your specific requirements
  4. Review the output - Always review generated code for security and correctness
💡 Pro Tip: For best results, provide context about your project structure and any specific constraints or preferences you have.

Best Practices

  • ✓ Always review generated code for security vulnerabilities before deploying
  • ✓ Test the caching code in a development environment first
  • ✓ Customize the prompt output to match your project's coding standards
  • ✓ Keep your AI assistant's context window in mind for complex requirements
  • ✓ Version control your prompts alongside your code for reproducibility

Frequently Asked Questions

Can I use this caching prompt commercially?

Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.

Which AI assistants work best with this prompt?

This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.

How do I customize this prompt for my specific needs?

You can modify the prompt by adding specific requirements, constraints, or preferences. For caching projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...