Search Results for

    Show / Hide Table of Contents
    View Source

    Class SafeLazy

    Provides methods for creating and working with lazy values that safely handle exceptions.

    Inheritance
    object
    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 Source

    GetSafeLazy(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.

    View Source

    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 true, only returns the value if already created; otherwise returns Umbraco.Cms.Core.Cache.SafeLazy.ValueNotCreated.

    Returns
    Type Description
    object

    The lazy value, Umbraco.Cms.Core.Cache.SafeLazy.ValueNotCreated if not yet created and onlyIfValueIsCreated is true, or null if an exception occurred.

    • View Source
    In this article
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX