🐹 @cache Operator in TuskLang - Go Guide

Go Documentation

@cache Operator in TuskLang - Go Guide

⚑ Speed Demon: @cache Operator Mastery

TuskLang's @cache operator is your performance superweapon. We don't bow to any kingβ€”especially not slow, repeated operations. Here's how to use @cache in Go projects to turbocharge your configuration performance.

πŸ“‹ Table of Contents

- What is @cache? - Basic Usage - TTL Configuration - Cache Strategies - Go Integration - Best Practices

🧠 What is @cache?

The @cache operator caches expensive operations and their results. No more repeated database queries or HTTP callsβ€”just pure, cached performance.

πŸ› οΈ Basic Usage

[metrics]
user_count: @cache("5m", @query("SELECT COUNT(*) FROM users"))
api_status: @cache("1m", @http("GET", "https://api.example.com/status"))

⏱️ TTL Configuration

[performance]
short_cache: @cache("30s", expensive_operation)
medium_cache: @cache("5m", medium_operation)
long_cache: @cache("1h", long_operation)

🎯 Cache Strategies

Database Query Caching

[stats]
user_count: @cache("5m", @query("SELECT COUNT(*) FROM users"))
order_count: @cache("2m", @query("SELECT COUNT(*) FROM orders WHERE created_at > NOW() - INTERVAL '1 day'"))

HTTP Request Caching

[external]
weather: @cache("15m", @http("GET", "https://api.weather.com/current"))

Computed Value Caching

[calculations]
total_revenue: @cache("10m", @calculate("SELECT SUM(amount) FROM transactions"))

πŸ”— Go Integration

userCount := config.GetInt("user_count") // Automatically cached
apiStatus := config.GetString("api_status") // Automatically cached

Manual Cache Management

cache := tusklang.NewCache(5 * time.Minute)
cache.Set("key", "value")
val, found := cache.Get("key")

πŸ₯‡ Best Practices

- Cache expensive operations (queries, HTTP calls) - Use appropriate TTL for your data - Invalidate cache when data changes - Monitor cache hit rates

---

TuskLang: Speed is power with @cache.