Cache
MRU/LRU object cache
cache := Collection.Cache->New(Cache->Type->LRU, 3)<IntRef, String>;
cache->Insert(415, "San Francisco");
cache->Insert(925, "East Bay");
cache->Insert(650, "Mountain View");
cache->Find(650)->PrintLine();
cache->Find(650)->PrintLine();
cache->Find(415)->PrintLine();
cache->Find(925)->PrintLine();
cache->Find(925)->PrintLine();
cache->Insert(510, "Oakland");
cache->Find(510)->PrintLine();
cache->Find(510)->PrintLine();
cache->Find(510)->PrintLine();
"---"->PrintLine();
values := cache->GetKeys()<IntRef>;
each(value := values) {
value->PrintLine();
};Operations
Find
Searches for a value in cache
method : public : Find(key:K) ~ SParameters
| Name | Type | Description |
|---|---|---|
| key | K | search key |
Return
| Type | Description |
|---|---|
| S | found value, Nil if not found |
GetKeyValues
Gets a collection of key/value pairs
method : public : GetKeyValues() ~ Vector<Pair<K,S>>Return
| Type | Description |
|---|---|
| Vector<Pair<K,S>> | vector of key/value pairs |
GetKeys
Get a collection of keys
method : public : GetKeys() ~ Vector<K>Return
| Type | Description |
|---|---|
| Vector<K> | vector of keys |
GetValues
Gets a collection of values
method : public : GetValues() ~ Vector<S>Return
| Type | Description |
|---|---|
| Vector<S> | vector of values |
Has
Checks for a value in a cache
method : public : Has(key:K) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| key | K | search key |
Return
| Type | Description |
|---|---|
| Bool | true if found, false otherwise |
Insert
Inserts a value into the hash
method : public : Insert(key:K, value:S) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| key | K | key |
| value | S | value |
IsEmpty
Checks to see if the cache is empty
method : public : IsEmpty() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if empty, false otherwise |
New
Default constructor
New(type:Cache->Type, max:Int)Parameters
| Name | Type | Description |
|---|---|---|
| type | Cache->Type | MRU or LRU cache |
| max | Int | cache max size |
Remove
Removes a value from the cache
method : public : Remove(key:K) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| key | K | key for value to remove |
ToString
Formats the collection into a string. If an element implements the 'Stringify' interface, it's 'ToString()' is called.
method : public : ToString() ~ StringReturn
| Type | Description |
|---|---|
| String | string representation |