Class SafeLazy
Provides methods for creating and working with lazy values that safely handle exceptions.
Inheritance
Namespace: Umbraco.Cms.Core.Cache
Assembly: Umbraco.Core.dll
Syntax
public static class SafeLazy
Remarks
Safe lazy values capture exceptions during evaluation and return them as null values instead of re-throwing, preventing cache corruption from failed evaluations.
Methods
View SourceGetSafeLazy(Func<object?>)
Creates a safe lazy that catches exceptions during evaluation.
Declaration
public static Lazy<object?> GetSafeLazy(Func<object?> getCacheItem)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<object> | getCacheItem | The factory function to create the cached item. |
Returns
| Type | Description |
|---|---|
| Lazy<object> | A lazy value that wraps exceptions in an SafeLazy.ExceptionHolder instead of throwing. |
GetSafeLazyValue(Lazy<object?>?, bool)
Gets the value from a safe lazy, returning null for exceptions.
Declaration
public static object? GetSafeLazyValue(Lazy<object?>? lazy, bool onlyIfValueIsCreated = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Lazy<object> | lazy | The lazy value to evaluate. |
| bool | onlyIfValueIsCreated | If |
Returns
| Type | Description |
|---|---|
| object | The lazy value, Umbraco.Cms.Core.Cache.SafeLazy.ValueNotCreated if not yet created and |