stash 1.0.0-dev.1 stash: ^1.0.0-dev.1 copied to clipboard
Standard caching API for Dart. Defines a common mechanism to create, access, update, and remove information from caches. Provides a in memory reference implementation
import 'package:stash/stash_memory.dart';
class Task {
final int id;
final String title;
final bool completed;
Task({this.id, this.title, this.completed = false});
@override
String toString() {
return 'Task ${id}: "${title}" is ${completed ? "completed" : "not completed"}';
}
}
void main() async {
// Creates a memory based cache with a a capacity of 10
final cache = newMemoryCache(maxEntries: 10);
// Adds a task with key 'task1' to the cache
await cache.put(
'task1', Task(id: 1, title: 'Run stash_memory example', completed: true));
// Retrieves the value from the cache
final value = await cache.get('task1');
print(value);
}