Commit e3a5c4d3 authored by nanahira's avatar nanahira

entry

parent a942ac11
Pipeline #14783 canceled with stages
in 3 minutes and 50 seconds
# Aragami
Another cache service.
\ No newline at end of file
Another cache ORM.
## Use
```ts
const aragami = new Aragami({
// Defaults to memory store, but to specify redis property you may use Redis store.
redis: {
url: 'redis://localhost:6379',
}
});
@CachePrefix('user')
@CacheTTL(30000)
class User {
@CacheKey() // Required. To cache with key of this field. Put a function inside to transform.
@LockKey() // Specifies a key for lock.
name: string;
@LockKey() // Multiple lock keys can be specified.
age: string;
}
async function main() {
const user = new User();
user.name = 'John';
user.age = '30';
await aragami.set(user); // Set with specific object.
const user2 = await aragami.get(User, 'John');
const keys = await aragami.keys(User);
const values = await aragami.values(User);
const entries = await aragami.entries(User);
await aragami.delete(user2);
await aragami.clear(User);
// wraps a function with cache.
const readUser = aragami.wrap(
User,
(name: string) => database.get(name), // For data fetching
(name) => name, // Specify cache key.
);
const userFromCache = await readUser('John');
// wraps a function with lock.
const saveUser = aragami.lock(
(user: User) => database.save(user), // Lock process
(user) => [user], // Specify lock key. Can be an array.
)
await saveUser(user);
}
```
export * from './src/aragami';
export * from './src/def';
export * from './src/decorators';
export * from './src/wrappers';
{
"name": "myproject",
"description": "myproject-desc",
"name": "aragami",
"description": "Another cache ORM.",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......@@ -12,15 +12,15 @@
},
"repository": {
"type": "git",
"url": "https://code.mycard.moe/3rdeye/myproject.git"
"url": "https://code.mycard.moe/3rdeye/aragami.git"
},
"author": "Nanahira <nanahira@momobako.com>",
"license": "MIT",
"keywords": [],
"bugs": {
"url": "https://code.mycard.moe/3rdeye/myproject/issues"
"url": "https://code.mycard.moe/3rdeye/aragami/issues"
},
"homepage": "https://code.mycard.moe/3rdeye/myproject",
"homepage": "https://code.mycard.moe/3rdeye/aragami",
"jest": {
"moduleFileExtensions": [
"js",
......
......@@ -39,7 +39,10 @@ export class Aragami {
return o;
}
const keyTransformer = reflector.get('AragamiCacheKey', o);
return keyTransformer ? await keyTransformer(o) : '';
if (!keyTransformer) {
throw new Error(`No key metadata found for ${o.constructor.name}`);
}
return await keyTransformer(o);
}
private getTTL(o: any) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment