#cache->clear() → number KScript.Cache
<echo>{ $cache->clear() } keys removed</echo>echo "{ $cache->clear() } keys removed"Un champ est une information simple sur la valeur, lue avec un point et sans crochets : $value.name. Une méthode prend des arguments ou effectue un traitement, et s'appelle avec -> : $value->name(arguments), ou avec la valeur transmise par un pipe : $value |> name(arguments).
| Champ | Type | Description |
|---|---|---|
.kind | string | Où les valeurs sont conservées : en mémoire, dans un fichier ou dans une base de données. |
.name | string | Le nom du magasin, qui garde ses clés séparées de celles des autres magasins. |
Celles-ci nécessitent <import package="KScript.Cache" />import KScript.Cache. Voir KScript.Cache.
cache->clear() → number KScript.Cache<echo>{ $cache->clear() } keys removed</echo>echo "{ $cache->clear() } keys removed"cache->clear_group(name: string) → number KScript.Cache| Paramètre | Prend |
|---|---|
name obligatoire | string |
<do>$cache->group('users')->set('1', 'Joan')</do>
<echo>{ $cache->clear_group('users') } removed</echo>$cache->group('users')->set('1', 'Joan')
echo "{ $cache->clear_group('users') } removed"cache->get(key, default?) → any KScript.CacheLes arguments peuvent être nommés : ->get(…, default: …).
<do>$cache->set('greeting', 'hello')</do>
<echo>{ $cache->get('greeting') } { $cache->get('missing', default: 'none') }</echo>$cache->set('greeting', 'hello')
echo "{ $cache->get('greeting') } { $cache->get('missing', default: 'none') }"cache->group(name: string) → cache KScript.Cache| Paramètre | Prend |
|---|---|
name obligatoire | string |
<let name="users" value="$cache->group('users')" />
<do>$users->set('1', 'Joan')</do>
<echo>{ $users->get('1') } { $cache->get('1', default: 'not in the main cache') }</echo>$users = $cache->group('users')
$users->set('1', 'Joan')
echo "{ $users->get('1') } { $cache->get('1', default: 'not in the main cache') }"cache->has(key) → bool KScript.Cache<do>$cache->set('token', 'abc', ttl: 5m)</do>
<echo>{ $cache->has('token') }</echo>$cache->set('token', 'abc', ttl: 5m)
echo $cache->has('token')cache->increment(key, by?: number, ttl?: duration) → number KScript.CacheLes arguments peuvent être nommés : ->increment(…, by: …, ttl: …).
<do>$cache->increment('visits'); $cache->increment('visits', by: 2)</do>
<echo>{ $cache->get('visits') }</echo>$cache->increment('visits')
$cache->increment('visits', by: 2)
echo $cache->get('visits')cache->keys() → list KScript.Cache<do>$cache->set('a', 1); $cache->set('b', 2)</do>
<echo>{ $cache->keys() }</echo>$cache->set('a', 1)
$cache->set('b', 2)
echo $cache->keys()cache->lock(key, ttl: duration, work: fn, wait?: duration) → any KScript.Cache| Paramètre | Prend |
|---|---|
key obligatoire | n'importe quelle valeur |
ttl obligatoire | durée |
work obligatoire | fn |
wait facultatif | durée |
Les arguments peuvent être nommés : ->lock(…, ttl: …, work: …).
<let name="report" value="$cache->lock('report', ttl: 1m, work: fn() => 'built once')" />
<echo>{ $report }</echo>$report = $cache->lock('report', ttl: 1m, work: fn() => 'built once')
echo $reportcache->pull(key, default?) → any KScript.CacheLes arguments peuvent être nommés : ->pull(…, default: …).
<do>$cache->set('code', 1234)</do>
<echo>{ $cache->pull('code') } { $cache->pull('code', default: 'gone') }</echo>$cache->set('code', 1234)
echo "{ $cache->pull('code') } { $cache->pull('code', default: 'gone') }"cache->remember(key, compute: fn, ttl?: duration) → any KScript.CacheLes arguments peuvent être nommés : ->remember(…, compute: …, ttl: …).
<let name="squares" value="$cache->remember('squares', fn() => [1, 2, 3]->map(fn(n) => $n * $n), ttl: 10m)" />$squares = $cache->remember('squares', fn() => [1, 2, 3]->map(fn(n) => $n * $n), ttl: 10m)cache->remove(key) → bool KScript.Cache<do>$cache->set('draft', 'hi'); $cache->remove('draft')</do>
<echo>{ $cache->has('draft') }</echo>$cache->set('draft', 'hi')
$cache->remove('draft')
echo $cache->has('draft')cache->set(key, value, ttl?: duration) → any KScript.Cache| Paramètre | Prend |
|---|---|
key obligatoire | n'importe quelle valeur |
value obligatoire | n'importe quelle valeur |
ttl facultatif | durée |
Les arguments peuvent être nommés : ->set(…, value: …, ttl: …).
<do>$cache->set('user:1', { name: 'Joan' }, ttl: 600)</do>$cache->set('user:1', { name: 'Joan' }, ttl: 600)cache->set_if_absent(key, value, ttl?: duration) → bool KScript.Cache| Paramètre | Prend |
|---|---|
key obligatoire | n'importe quelle valeur |
value obligatoire | n'importe quelle valeur |
ttl facultatif | durée |
Les arguments peuvent être nommés : ->set_if_absent(…, value: …, ttl: …).
<echo>{ $cache->set_if_absent('lock:report', 'me', ttl: 1m) } { $cache->set_if_absent('lock:report', 'you') }</echo>echo "{ $cache->set_if_absent('lock:report', 'me', ttl: 1m) } { $cache->set_if_absent('lock:report', 'you') }"cache->ttl(key) → duration KScript.Cache<do>$cache->set('code', 1234, ttl: 1m)</do>
<echo>{ $cache->ttl('code') } left</echo>$cache->set('code', 1234, ttl: 1m)
echo "{ $cache->ttl('code') } left"->convert(from?: 'json'|yaml|'csv'|'markdown'|'latex', to?: 'json'|yaml|'csv'|html|'markdown'|'latex', header?: bool, as?: type, headers?: list, indented?: bool)->from(type: 'json'|yaml|'csv'|'markdown'|'latex', header?: bool, as?: type)->is_a(type: word)->is_null()->or(fallback)->to(type: 'json'|yaml|'csv'|html|'markdown'|'latex', headers?: list, indented?: bool)->to_string()->type()