Compare commits

...

3 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 6e11752590 ConfigType
- Documented enum members
2024-04-27 13:48:41 +02:00
Tristan B. Velloza Kildaire 46eeaa4430 README
- Updated
2024-04-27 13:46:41 +02:00
Tristan B. Velloza Kildaire 0d2742260b
CacheMap (#19)
- Added `opIndex(K)` support

CacheMap (unittests)

- Make use of the newly added `opIndex(K)` support
2024-04-27 13:45:04 +02:00
3 changed files with 32 additions and 7 deletions

View File

@ -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

View File

@ -39,9 +39,24 @@ private union ConfigValue
*/
public enum ConfigType
{
/**
* A string
*/
TEXT,
/**
* An integer
*/
NUMERIC,
/**
* A boolean
*/
FLAG,
/**
* A string array
*/
ARRAY
}

View File

@ -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