Skip to content

Property Cache

Namespace: Belay.Attributes
Assembly: Belay.Attributes.dll

Cache

Gets or sets a value indicating whether gets or sets whether the method should be cached on the device. When true, the method code is deployed once and reused for subsequent calls. When false, the code is sent for each invocation.

csharp
public bool Cache { get; set; }

Property Value

bool

Examples

[Task(Cache = false)]
public async Task<string> GetDiagnosticInfoAsync()
{
    // This method's code is sent fresh each time
    // Useful for debugging or infrequent operations
    return await ExecuteAsync<string>(@"
        import gc, sys
        f'Memory: {gc.mem_free()}, Platform: {sys.platform}'
    ");
}

Remarks

Caching improves performance by avoiding repeated code deployment, but may consume device memory. Disable caching for methods that are called infrequently or when device memory is constrained.

Cached methods are automatically invalidated and redeployed if the method implementation changes between application runs.

Released under the Apache License 2.0.