stash 2.0.0 stash: ^2.0.0 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
stash #
The base stash
library.
Overview #
This package provides the foundations of the stash
caching library upon which specific implementations of storage mechanisms and 3rd party library integrations rely upon. It sports a in-memory implementation that is perfectly suitable for the majority of the use cases providing a rather efficient way of avoiding repeatable calls to heavyweight resources.
Getting Started #
Add this to your pubspec.yaml
replacing x.x.x
with the latest version of the stash
library
dependencies:
stash: ^x.x.x
Run the following command to install dependencies:
pub get
Optionally use the following command to run the tests:
pub run test
Finally, to start developing import the library:
import 'package:stash/stash_memory.dart';
Usage #
The example bellow creates a cache with a in-memory storage backend that supports a maximum of 10 Task
objects. In this rather simple use case there is no need to provide methods to serialize/deserialize the object as the object stays in-memory. Please take a look at the documentation of stash to gather additional information about the available APIs and to explore the full range of capabilities of the stash
library
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 maximum of 10 entries
final cache = newMemoryCache(maxEntries: 10);
// Adds a task with key 'task1' to the cache
await cache.put(
'task1', Task(1, 'Run stash_memory example', completed: true));
// Retrieves the value from the cache
final value = await cache.get('task1');
print(value);
}
Contributing #
Contributions are always welcome!
If you would like to contribute, feel free to make a Github pull request as we are always looking for contributions for:
- Tests
- Documentation
- New APIs
See CONTRIBUTING.md for ways to get started.
Features and Bugs #
Please file feature requests and bugs at the issue tracker.
License #
This project is licensed under the MIT License - see the LICENSE file for details