vyuh_cache 1.4.5 copy "vyuh_cache: ^1.4.5" to clipboard
vyuh_cache: ^1.4.5 copied to clipboard

A flexible caching solution for Vyuh Framework Apps, offering time-based caching with pluggable storage backends to reduce API calls and boost performance.

Vyuh Logo

Vyuh Framework

Build Modular, Scalable, CMS-driven Flutter Apps

Docs | Website

Vyuh Cache ๐Ÿ’พ #

vyuh_cache

A lightweight, flexible caching solution for Vyuh-framework applications. Provides time-based caching with pluggable storage backends. Perfect for reducing API calls, improving app performance, and managing temporary data.

Features โœจ #

  • Time-based Caching: Automatic expiration with TTL (Time To Live) โฑ๏ธ
  • Type Safety: Generic implementation for type-safe caching ๐Ÿ›ก๏ธ
  • Pluggable Storage: Built-in memory storage with extensible storage interface ๐Ÿ’พ
  • Async API: Full async support for all operations โšก
  • Value Generation: Built-in support for generating missing cache values ๐Ÿ”„
  • Expiration Handling: Automatic cleanup of expired entries ๐Ÿงน

Installation ๐Ÿ“ฆ #

Add this to your package's pubspec.yaml:

dependencies:
  vyuh_cache: any
copied to clipboard

Usage ๐Ÿ’ก #

Basic Usage #

// Create a cache instance with memory storage
final cache = Cache(
  CacheConfig(
    storage: MemoryCacheStorage<String>(),
    ttl: Duration(minutes: 5),
  ),
);

// Store a value
await cache.set('greeting', 'Hello, World!');

// Check if key exists
if (await cache.has('greeting')) {
  // Retrieve the value
  final value = await cache.get('greeting');
  print(value); // Hello, World!
}
copied to clipboard

Value Generation #

// Get value with automatic generation if missing
final value = await cache.build(
  'user-123',
  generateValue: () async {
    // Expensive operation (e.g., API call)
    return await fetchUserFromApi('123');
  },
);
copied to clipboard

Cache Management #

// Remove a specific entry
await cache.remove('old-key');

// Clear all entries
await cache.clear();
copied to clipboard

Custom Storage #

Implement CacheStorage interface for custom storage backends:

class RedisStorage<T> implements CacheStorage<T> {
  @override
  Future<CacheEntry<T>?> get(String key) async {
    // Implement Redis get
  }

  @override
  Future<void> set(String key, CacheEntry<T> value) async {
    // Implement Redis set
  }

  // ... implement other methods
}
copied to clipboard

Best Practices ๐ŸŽฏ #

  1. Choose Appropriate TTL: Set TTL based on data volatility
  2. Handle Errors: Always handle potential cache misses
  3. Type Safety: Use specific types instead of dynamic
  4. Memory Management: Clear unused cache entries
  5. Storage Selection: Use appropriate storage for your use case

Learn More ๐Ÿ“š #


Made with โค๏ธ by Vyuh

3
likes
150
points
148
downloads

Publisher

verified publishervyuh.tech

Weekly Downloads

2024.09.08 - 2025.03.23

A flexible caching solution for Vyuh Framework Apps, offering time-based caching with pluggable storage backends to reduce API calls and boost performance.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#cache #vyuh #system

Documentation

API reference

License

unknown (license)

Dependencies

crypto, json_annotation

More

Packages that depend on vyuh_cache