-
Notifications
You must be signed in to change notification settings - Fork 3
/
cache.gtw
74 lines (48 loc) · 3.67 KB
/
cache.gtw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
~~LANG:FR@frman:cache~~
jCache is a class to store any data in a cache system like memcache. It supports other kind of storage like files or a SQL database.
Note that jCache doesn't use jKVDb as a backend, but it could use it in next versions.
===== Configuration =====
You should declare storages in a @@F@var/config/profiles.ini.php@@ file. See [[config#the-profiles.ini.php-file|the corresponding chapter]] to know how to use this file. It may contain some section, corresponding to a "profile", like for jDb or jKVDb.
The connection type to indicate in profile names is @@jcache@@.
Each profile must declare these properties:
* @@driver@@: the driver name for the storage backend
* @@enabled@@: to enable or disable the cache for this profile (@@1@@ or @@0@@). You can then disable the cache without modifying your classes, when you develop or want to debug something.
* @@ttl@@: the default time to live of data, in seconds. 0 means no timeout.
Depending of the driver, you may have additional parameters.
==== memcache backend ====
It is a driver for memcache, using the memcache API of PHP (not memcached API).
The configuration parameter is @@server@@, containing a list of host and port.
<code>
[jcache:mymemcache]
driver=memcache
ttl=360
enabled=1
servers = memcache_host1:11211,memcache_host2:11211,memcache_host3:11211
</code>
==== file backend ====
It is similar to the file driver of jKVDb. Here are its configuration parameters:
* @@driver=file@@
* @@cache_dir@@: the directory where to store the files. by default: @@F@temp/yourapp/cache/@@.
* @@file_locking=1@@ to disable or enable file locking (keep to 1 is better)
* @@directory level@@: Set the directory structure level. 0 means "no directory structure", 1 means "one level of directory", 2 means "two levels"...
* @@directory_umask@@: umask for directory structure (default '0700')
* @@file_name_prefix@@: prefix for cache files (default 'jelix_cache')
* @@cache_file_umask@@: umask for cache files (default '0600')
==== sql backend ====
This driver uses a sql table to store cache values. The installer of jelix creates the needed table if you use this backend. If it is already installed, during developpement, use one of the @@F@lib/jelix/core-modules/jelix/install/sql/install_jcache.schema.*@@ files to create the table.
Configuration parameters:
* @@dao@@: indicates the dao to use. By default, jelix~cache.
* @@dbprofile@@: the jDb profile to use.
===== Using jCache =====
To store and read from the cache system, call one of the static methods of jCache.
* @@M@jCache::get($key)@@: to retrieve the value corresponding to the given key.
* @@M@jCache::set($key, $value, $ttl)@@: to store a new value or modify an existing value. $ttl is optional
* @@M@jCache::delete($key)@@: delete the given key-value
* @@M@jCache::increment($key)@@: increment the value. You can indicate also the value of the incrementation
* @@M@jCache::decrement($key)@@: decrement the value. You can indicate also the value of the decrementation
* @@M@jCache::add($key, $value)@@: to store a new value. return false if the key already exists
* @@M@jCache::replace($key,$value, $ttl)@@: to change the value of the corresponding key. If the key doesn't exist, it returns false. $ttl is optional.
* @@M@jCache::garbage()@@: delete all expired keys
* @@M@jCache::flush()@@: delete all keys
* @@M@jCache::call($fn, $fnargs, $ttl)@@: get the value corresponding to the function name/args. If it is not set, call the function $fn with arguments $fnargs, which should return a value. This value is then put into the cache.
All this static methods accept as last argument a profile. By default, the "default" profile will be used.