CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418346
1
2
3 Caches
3
4
5
3.1 Object constructors
6
7
Caches are objects which store for a fixed number of keys a value, so they
8
are a map Obj^k -> Obj, while the k is fixed. A cache ususally stores the
9
result in a weak pointer list, which means that if the value which the cache
10
should store is not referenced in the system anymore, it will not be
11
remembered by the cache. However, caches can be set to store the value
12
permanently (crisp), or not to store any new value at all (inaktive). In
13
that case, already stored values are still in the cache and can be accessed
14
once the cache is set active again.
15
16
3.1-1 CachingObject
17
18
CachingObject( [k, ][is_crisp] )  operation
19
CachingObject( arg )  operation
20
CachingObject( arg1, arg2 )  operation
21
Returns: a cache
22
23
If no argument is given, the function returns a weak cache with key length
24
one, if an integer k is given, a weak cache with key length k, and if the
25
bool is_crisp is true, a crisp cache with the corresponding length.
26
27
3.1-2 CachingObject
28
29
CachingObject( object, cache_name, length[, is_crisp] )  operation
30
CachingObject( arg1, arg2, arg3, arg4 )  operation
31
32
This methods are not installed, they serve as an interface for
33
InstallMethodWithCacheFromObject.
34
35
36
3.2 Setters, getters
37
38
3.2-1 CacheValue
39
40
CacheValue( cache, key )  operation
41
Returns: stored value
42
43
If there is a value stored in the cache for key, which can be a single key
44
for caches with key length one or a list of keys depending on the key length
45
of the cache, this method returns a list only contraining the value,
46
otherwise an empty list.
47
48
3.2-2 SetCacheValue
49
50
SetCacheValue( cache, key, value )  operation
51
52
Sets the value of key of the cache to value.
53
54
3.2-3 IsEqualForCache
55
56
IsEqualForCache( obj1, obj2 )  operation
57
Returns: true or false
58
59
This function is used to compare objects for the caches. The standard way is
60
IsIdenticalObj, and lists are compared recursive with this function. It is
61
possible and recommended to overload this function as needed.
62
63
64
3.3 Managing functions
65
66
3.3-1 SetCachingObjectCrisp
67
68
SetCachingObjectCrisp( cache )  function
69
Returns: nothing
70
71
Sets the caching to crisp, weak, or deativates the cache completely.
72
73
3.3-2 SetCachingObjectWeak
74
75
SetCachingObjectWeak( arg )  function
76
77
3.3-3 DeactivateCachingObject
78
79
DeactivateCachingObject( arg )  function
80
81
82
3.4 Install functions
83
84
3.4-1 InstallMethodWithCache
85
86
InstallMethodWithCache( Like, InstallMethod )  function
87
88
Installs a method like InstallMethod, but additionally puts a cache layer
89
around it so that the result is cached. It is possible to give the cache as
90
the option Cache, to use the same cache for more than one method or store it
91
somewhere to have access to the cache.
92
93
3.4-2 InstallMethodWithCrispCache
94
95
InstallMethodWithCrispCache( arg )  function
96
97
Like InstallMethodWithCache, but with a crisp cache.
98
99
3.4-3 InstallMethodWithCacheFromObject
100
101
InstallMethodWithCacheFromObject( Like, InstallMethod )  function
102
103
This works just like InstallMethodWithCache, but it extracts the cache via
104
the CachingObject method from one of its arguments. The CachingObject must
105
then be implemented for one of the arguments, and the option ArgumentNumber
106
can specify which option to be used. As second argument for CachingObject a
107
string is used, which can identify the cache. Standard is the name of the
108
operation, for which the method is installed, but it can be specified using
109
the CacheName option.
110
111
3.4-4 FunctionWithCache
112
113
FunctionWithCache( func )  function
114
Returns: a function
115
116
Creates a cached function out of a given function func. If the option Cache
117
is a cache, this cache is used. If the option Cache is the string crisp, a
118
crisp cache is used. All other values for this option lead to a single weak
119
cache.
120
121
122