-
Notifications
You must be signed in to change notification settings - Fork 3
Cache
Caching in TestPipe is provided through a static property named Cache in the TestSession class. The TestPipe cache is implemented in the TestPipe.Core namespace in a class named Cache<TKey, TValue>. The Cache class is basically a key value dictionary.
Method | Description |
---|---|
void Add(TKey key, TValue value) | Adding a new cache key and value. |
void Clear(string keyPrefix) | Clearing cache values by key prefix. |
bool ContainsKey(string key) | Determining if the cache contains a specific key. |
TValue GetKeyValue(TKey key) | This is a protected method for getting individual values from the cache. |
TValue GetKeyValue(TKey key) | This is a protected method for getting individual values from the cache. |
Since the cache is global to a TestSession, we prefix cache keys with a value to lessen conflicts when caching values for different TestSession contexts (e.g. suite, features, scenarios, steps...).
With this we can remove all values for a particular context. If we have a key prefix named "Feature_12" attached to all cache keys for a feature with Id of 12, when the feature 12 test run is complete, we can delete all of its cache values by calling the Clear method on the Cache passing it the key prefix we want to remove values for.
###Key Not Found If an attempt is made to get a key value for a key that does not exist in the cache, a KeyNotFoundException will be thrown. You should first check for the existence of a key with the ContainsKey method or you should catch the KeyNotFoundException when your code should not fail because of a missing key.
###Restricted Use The Cache class is not restricted to use outside of TestPipe, but it should only be used through the TestSession class. The Cache class provides a public API, but if it is used in a manner that corrupts or affects the integrity of the keys or values, the results of tests may be affected.
Home | Getting Started | Documentation | Contribute | Copyright © 2014 Charles Bryant