Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidation cache #5

Merged
merged 5 commits into from
Apr 18, 2024
Merged

Invalidation cache #5

merged 5 commits into from
Apr 18, 2024

Conversation

Burgyn
Copy link
Member

@Burgyn Burgyn commented Apr 17, 2024

Cache invalidation

You can invalidate cache entries by tags defined in tag templates.

Automatic by endpoints

{
    "Key": "deleteProduct",
    "UpstreamHttpMethod": [ "Delete" ],
    "DownstreamPathTemplate": "/api/producsts/{id}",
    "UpstreamPathTemplate": "/products/{id}",
    "InvalidateCache": ["product:{tenantId}", "product:{tenantId}:{id}"], // 👈 Invalidate cache by tags
}

Manual

public class ProductsService {
    private readonly IOutputCacheStore _outputCacheStore;

    public ProductsService(IOutputCacheStore outputCacheStore)
    {
        _outputCacheStore = outputCacheStore;
    }

    public async Task DeleteProduct(int tenantId, int id)
    {
        // 👇 Invalidate cache by tags
        await _outputCacheStore.InvalidateAsync($"product:{tenantId}", $"product:{tenantId}:{id}");
        // ...
    }
}

"UpstreamHttpMethod": [ "Delete" ],
"DownstreamPathTemplate": "/api/producsts/{id}",
"UpstreamPathTemplate": "/products/{id}",
"InvalidateCache": ["product:{tenantId}", "product:{tenantId}:{id}"], // 👈 Invalidate cache by tags

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nebolo by lepšie nazvať to InvalidateCacheTags?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ja som nad tým tiež rozmýšľal. Ale povedal som si, že to tam nedám lebo invalidacia podľa tagov je vlastne štandard v tomto type kešovanie, takže by to tam za mňa bola zbytočná informácia.

@@ -397,6 +415,8 @@ private class Store : IOutputCacheStore

public bool WasCallSetAsync { get; private set; }

public string EvicedTags { get; private set; } = string.Empty;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Evicted

@Burgyn Burgyn merged commit 1aae6ad into master Apr 18, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants