Versions Compared
compared with
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Excerpt |
---|
Define a new Cache.key and it's associated settings. |
Syntax
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
Cache(key, fn, ttl); |
Parameters
Parameter | Type | Mandatory | Notes | API Version |
---|---|---|---|---|
key | String | The "key" (name) of the cache | 1.0.1 | |
fn | Function Variant | A function that will generate new data when the cache expires 0.1. Or a static primitive, object or array value. Note: This also causes ttl to default to -1. | 1.0 | |
ttl | Number | The "time to live" which defines how long data will be cached for before it expires:
It's important to note that game time doesn't necessarily run at the same speed as real world time – users can speed up or slow down the game (in single player games) or lag can stall game time (in multiplayer games), and slow running scripts can also cause game lag (in both single player and multiplayer games). Default: -1 | 1.0.1 |
Return value
The function does not return anything.
Examples
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
Cache( "foo", function() { return "gameTime: "+gameTime+" (requires manual refresh)"; }, -1 // negative ttl = manual refresh mode ); console(cache.foo); // outputs same time until you refresh the cache // to refresh the cache (this works on any cache): Cache.foo = void Cache; |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
Cache( "foo", function() { return "gameTime: "+gameTime+" (updates when gameTime changes)"; }, 0 // zero ttl = update whenever gameTime changes ); console(cache.foo); // outputs current gameTime |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
Cache( "foo", function() { return "gameTime: "+gameTime+" (updates every game second)"; }, 1000 // cache will last for 1 game second ); console(cache.foo); // time changes every second *of game time* |
Div | ||||||
---|---|---|---|---|---|---|
| ||||||
Availability
Requires:
|
Div | ||||
---|---|---|---|---|
| ||||
ContentsJump to:
|
Div | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
Cache APITopics:
|