Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/polywrap/cache
It is a caching library for the wrappers. Wrappers can store and retrieve data in cache using this library.
https://github.com/polywrap/cache
Last synced: about 2 months ago
JSON representation
It is a caching library for the wrappers. Wrappers can store and retrieve data in cache using this library.
- Host: GitHub
- URL: https://github.com/polywrap/cache
- Owner: polywrap
- License: mit
- Created: 2023-04-26T12:51:59.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-05-09T15:21:07.000Z (over 1 year ago)
- Last Synced: 2024-08-02T15:04:02.410Z (5 months ago)
- Language: Python
- Size: 247 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-polywrap - Cache - A caching interface for the wraps, to be used for long-term data persistence. (Wraps)
README
# Cache
It is a caching library for the wrappers. Wrappers can store and retrieve data in cache using this library.This library has been implemented in an easily extensible way. It provides a common caching interface that can be shared across various caching implementations. We have already implemented the in-memory cache implementation and will be adding more such implementations, like local-storage, memcache, redis, ceramic, etc.
## Usage
- **If you are a Wrapper Developer** -
You just need to import the Cache interface, and you can get all the implementations that the Polywrap client has registered from within the wrapper using the `Interface.getImplementations` function.
You can use one or all of the implementations to store and retrieve data from the cache.
Alternatively, you can specify the uri of the particular implementation that you want to support.- Schema
```graphql
#import * into Interface from "wrap://ens/interface.cache.polywrap.eth"
#use { getImplementations } for Interfacetype Module{
foo(key: String!, value: String!): Boolean!
}
```
- Wasm-as
```ts
import {
Interface,
Interface_Module,
Args_foo
} from "./wrap";export function foo(args: Args_foo) {
const impls = Interface.getImplementations();
if (impls.length < 1) {
throw new Error("...")
}
const cache = new Interface_Module(impls[0]);cache.set(Args_Foo.key, Args_Foo.value);
}
```
- **If you are an App Developer** - You need to register the implementations of the Cache interface using the client config.
```ts
const config = {
...,
plugins: [
...
{
uri: "wrap://ens/in-memory.cache.polywrap.eth"
plugin: InMemoryCachePlugin()
}
]
interfaces: [
{
interface: "wrap://ens/interface.cache.polywrap.eth",
implementations: [
"wrap://ens/in-memory.cache.polywrap.eth",
...
]
}
]
}
```