mirror of https://github.com/deavmi/niknaks
Compare commits
3 Commits
72671804a1
...
6e11752590
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | 6e11752590 | |
Tristan B. Velloza Kildaire | 46eeaa4430 | |
Tristan B. Velloza Kildaire | 0d2742260b |
|
@ -42,6 +42,8 @@ is expected to grow over time.
|
|||
* Things such as `CacheMap`
|
||||
* `niknaks.mechanisms`
|
||||
* User-defined input prompter, retry mechanisms
|
||||
* `niknaks.config`
|
||||
* Configuration entries and management
|
||||
|
||||
## License
|
||||
|
||||
|
|
|
@ -39,9 +39,24 @@ private union ConfigValue
|
|||
*/
|
||||
public enum ConfigType
|
||||
{
|
||||
/**
|
||||
* A string
|
||||
*/
|
||||
TEXT,
|
||||
|
||||
/**
|
||||
* An integer
|
||||
*/
|
||||
NUMERIC,
|
||||
|
||||
/**
|
||||
* A boolean
|
||||
*/
|
||||
FLAG,
|
||||
|
||||
/**
|
||||
* A string array
|
||||
*/
|
||||
ARRAY
|
||||
}
|
||||
|
||||
|
|
|
@ -357,6 +357,14 @@ public template CacheMap(K, V)
|
|||
return keyValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* See_Also: get
|
||||
*/
|
||||
public V opIndex(K key)
|
||||
{
|
||||
return get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given key
|
||||
* returning whether or
|
||||
|
@ -502,18 +510,18 @@ unittest
|
|||
CacheMap!(string, int) map = new CacheMap!(string, int)(&getVal, dur!("seconds")(10));
|
||||
|
||||
// Get the value
|
||||
int tValue = map.get("Tristan");
|
||||
int tValue = map["Tristan"];
|
||||
assert(tValue == 1);
|
||||
|
||||
// Get the value (should still be cached)
|
||||
tValue = map.get("Tristan");
|
||||
tValue = map["Tristan"];
|
||||
assert(tValue == 1);
|
||||
|
||||
// Wait for expiry (by sweeping thread)
|
||||
Thread.sleep(dur!("seconds")(11));
|
||||
|
||||
// Should call replacement function
|
||||
tValue = map.get("Tristan");
|
||||
tValue = map["Tristan"];
|
||||
assert(tValue == 2);
|
||||
|
||||
// Wait for expiry (by sweeping thread)
|
||||
|
@ -545,14 +553,14 @@ unittest
|
|||
CacheMap!(string, int) map = new CacheMap!(string, int)(&getVal, dur!("seconds")(5), dur!("seconds")(10));
|
||||
|
||||
// Get the value
|
||||
int tValue = map.get("Tristan");
|
||||
int tValue = map["Tristan"];
|
||||
assert(tValue == 1);
|
||||
|
||||
// Wait for 5 seconds (the entry should then be expired by then for on-access check)
|
||||
Thread.sleep(dur!("seconds")(5));
|
||||
|
||||
// Get the value (should have replacement function run)
|
||||
tValue = map.get("Tristan");
|
||||
tValue = map["Tristan"];
|
||||
assert(tValue == 2);
|
||||
|
||||
// Destroy the map (such that it ends the sweeper
|
||||
|
@ -577,14 +585,14 @@ unittest
|
|||
CacheMap!(string, int) map = new CacheMap!(string, int)(&getVal, dur!("seconds")(10), dur!("seconds")(10));
|
||||
|
||||
// Get the value
|
||||
int tValue = map.get("Tristan");
|
||||
int tValue = map["Tristan"];
|
||||
assert(tValue == 1);
|
||||
|
||||
// Remove the key
|
||||
assert(map.removeKey("Tristan"));
|
||||
|
||||
// Get the value
|
||||
tValue = map.get("Tristan");
|
||||
tValue = map["Tristan"];
|
||||
assert(tValue == 2);
|
||||
|
||||
// Destroy the map (such that it ends the sweeper
|
||||
|
|
Loading…
Reference in New Issue