Documentation

Cache

Deprecated: Please note that future versions of ThoughtFarmer will not support RazorEngine and Server C#. Please instead use JavaScript and fetch and update data via ajax and the Public REST API.


Get Method

Syntax:

public T Get<T>(string key)

Parameters:

Parameter Type Description
key string The cached item's key

Return value:

Type Description
T The element returned represented by T
 

Examples:

@{
    var userCount = Api.Cache.Get<int>("userCount");
}


Add Method

Syntax:

public void Add(string key, object value)

Parameters:

Parameter Type Description
key string The cached item's key
value object The object to store

Return value:

void

Examples:

@{
    Api.Cache.Add("userCount", 1234);
}


Add Method

Syntax:

public void Add(string key, object value, CacheExpiry cacheExpiry)

Parameters:

Parameter Type Description
key string The cached item's key
value object The object to store
cacheExpiry CacheExpiry A CacheExpiry object specifying either Absolute or Sliding expiry types

Return value:

void

Examples:

@{
    Api.Cache.Add("userCount", 1234, CacheExpiry.Sliding);
}


Set Method

Syntax:

public void Set(string key, object value)

Parameters:

Parameter Type Description
key string The cached item's key
value object The object to store

Return value:

void

Examples:

@{
    // updates an already stored cache item
    Api.Cache.Set("userCount", 1234);
}


Remove Method

Syntax:

public void Remove(string key)

Parameters:

Parameter Type Description
key string The cached item's key

Return value:

void

Examples:

@{
    Api.Cache.Remove("userCount");
}


Remove Method

Syntax:

public void Remove(int? contentId, int? parentId = null)

Parameters:

Parameter Type Description
contentId int? The cached item's content ID key
parentId (optional) int? The item's parent ID

Return value:

void

Examples:

@{
    Api.Cache.Remove(1234);

//or

Api.Cache.Remove(1234, 345);

}



Remove Method

Syntax:

public void Remove(int? contentId, int? parentId, bool includeChildren)

Parameters:

Parameter Type Description
contentId int? The cached item's content ID key
parentId int? The item's parent ID
includeChildren bool Whether children of this content item should be removed from cache

Return value:

void

Examples:

@{
    Api.Cache.Remove(1234, 345, true);
}

 

Contains Method

Syntax:

public bool Contains(string key)

Parameters:

Parameter Type Description
key string The cached item's key

Return value:

Type Description
bool Indicates whether the cached item exists in the cache
 

Examples:

@{
    var userCountExists = Api.Cache.Contains("userCount");
}