Store cache

View source code

View code example

Cache is an essential function of every system. We can use Yao's own cache function to store some temporary data.

handler list

processDescriptionDocumentation
cache.SetSet cache content-
cache.GetGet cache content-

Naming conventions

{
"name": "Cache",
"description": "Cache Description",
"type": "lru",
"option": {}
}

DSL structure

FieldDescription
namename
descriptiondescription
typeType: lru

example

Step 1: Create a new cache script file

Store uses cache, add file stores/cache.lru.json:

Application directory structure:

├── apis # Used to store interface description files
├── models # Used to store data model description files
├── db
└── stores # is used to store the cache directory
|
└── app.json

Step 2: Write the code cache.lru.json:

{
"name": "LRU Cache",
"description": "LRU cache",
"type": "lru",
"option": { "size": 102400 }
}

Step 3: Use the cache in any JS file, Set to set the cache, Get to get the cached data, and create a new scripts/test.js

function cacheOperation() {
var cache = new Store("cache");
cache.Set("key", "for bar .....");
var cache_info = cache.Get("key");
return cache_info;
}

run yao run scripts.test.cacheOperation

Introduce cache: new Store("cache"), set cache: cache.Set, get cache cache.Get("key")

Store cache

View source code

View code example

Cache is an essential function of every system. We can use Yao's own cache function to store some temporary data.

handler list

processDescriptionDocumentation
cache.SetSet cache content-
cache.GetGet cache content-

Naming conventions

{
"name": "Cache",
"description": "Cache Description",
"type": "lru",
"option": {}
}

DSL structure

FieldDescription
namename
descriptiondescription
typeType: lru

example

Step 1: Create a new cache script file

Store uses cache, add file stores/cache.lru.json:

Application directory structure:

├── apis # Used to store interface description files
├── models # Used to store data model description files
├── db
└── stores # is used to store the cache directory
|
└── app.json

Step 2: Write the code cache.lru.json:

{
"name": "LRU Cache",
"description": "LRU cache",
"type": "lru",
"option": { "size": 102400 }
}

Step 3: Use the cache in any JS file, Set to set the cache, Get to get the cached data, and create a new scripts/test.js

function cacheOperation() {
var cache = new Store("cache");
cache.Set("key", "for bar .....");
var cache_info = cache.Get("key");
return cache_info;
}

run yao run scripts.test.cacheOperation

Introduce cache: new Store("cache"), set cache: cache.Set, get cache cache.Get("key")