From 99a9474ef727d2facddbebe80bcf2a513464dc35 Mon Sep 17 00:00:00 2001 From: Josh-Heaps Date: Fri, 6 Mar 2026 17:05:48 -0700 Subject: [PATCH] Add cache invalidation --- .claude/settings.local.json | 6 +++-- .../Content/Blog/2026-03-06-my-first-post.md | 24 +++++++++++++++++++ JoshHeaps.Net/Controllers/BlogController.cs | 20 ++++++++++++++++ .../Services/Implementations/BlogService.cs | 6 +++++ .../Services/Interfaces/IBlogService.cs | 1 + JoshHeaps.Net/appsettings.json | 3 ++- 6 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 JoshHeaps.Net/Content/Blog/2026-03-06-my-first-post.md create mode 100644 JoshHeaps.Net/Controllers/BlogController.cs diff --git a/.claude/settings.local.json b/.claude/settings.local.json index b5c47f5..f18b55d 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -3,9 +3,11 @@ "allow": [ "Bash(dotnet test:*)", "Bash(dotnet build)", - "Bash(dir:*)" + "Bash(dir:*)", + "Bash(dotnet add:*)", + "Bash(dotnet build:*)" ], "deny": [], "ask": [] } -} \ No newline at end of file +} diff --git a/JoshHeaps.Net/Content/Blog/2026-03-06-my-first-post.md b/JoshHeaps.Net/Content/Blog/2026-03-06-my-first-post.md new file mode 100644 index 0000000..5554601 --- /dev/null +++ b/JoshHeaps.Net/Content/Blog/2026-03-06-my-first-post.md @@ -0,0 +1,24 @@ +--- +title: My First Post +date: 2026-03-06 +summary: Welcome to my blog! Here I'll share thoughts on software development, projects I'm working on, and things I find interesting. +tags: [dev, personal] +--- + +# Welcome to My Blog + +I've been meaning to start writing about the things I build and learn, and I'm finally getting around to it. + +## What to Expect + +I plan to write about: + +- **Projects** I'm working on, like this website and the other things on my portfolio +- **Software development** tips and patterns I find useful +- **Problem solving** approaches that have helped me grow as a developer + +## Why a Blog? + +Building things is great, but explaining *how* and *why* you built them is just as valuable. Writing forces you to organize your thoughts, and hopefully someone else finds it useful along the way. + +Stay tuned for more posts! diff --git a/JoshHeaps.Net/Controllers/BlogController.cs b/JoshHeaps.Net/Controllers/BlogController.cs new file mode 100644 index 0000000..ba16f2f --- /dev/null +++ b/JoshHeaps.Net/Controllers/BlogController.cs @@ -0,0 +1,20 @@ +using JoshHeaps.Net.Services.Interfaces; +using Microsoft.AspNetCore.Mvc; + +namespace JoshHeaps.Net.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class BlogController(IBlogService blogService, IConfiguration configuration) : ControllerBase +{ + [HttpPost("invalidate")] + public IActionResult InvalidateCache([FromHeader(Name = "X-Invalidate-Key")] string? key) + { + var expectedKey = configuration["BlogApi:InvalidateKey"]; + if (string.IsNullOrEmpty(expectedKey) || key != expectedKey) + return Unauthorized(); + + blogService.ClearCache(); + return Ok(); + } +} diff --git a/JoshHeaps.Net/Services/Implementations/BlogService.cs b/JoshHeaps.Net/Services/Implementations/BlogService.cs index 8d64442..a6ecad2 100644 --- a/JoshHeaps.Net/Services/Implementations/BlogService.cs +++ b/JoshHeaps.Net/Services/Implementations/BlogService.cs @@ -84,5 +84,11 @@ public class BlogService : IBlogService return result; } + public void ClearCache() + { + _cache.Clear(); + _logger.LogInformation("Blog cache cleared"); + } + private record CacheEntry(object Value, DateTime ExpiresAt); } diff --git a/JoshHeaps.Net/Services/Interfaces/IBlogService.cs b/JoshHeaps.Net/Services/Interfaces/IBlogService.cs index 2058177..624afe2 100644 --- a/JoshHeaps.Net/Services/Interfaces/IBlogService.cs +++ b/JoshHeaps.Net/Services/Interfaces/IBlogService.cs @@ -7,4 +7,5 @@ public interface IBlogService Task> GetAllPostsAsync(); Task GetPostBySlugAsync(string slug); Task> GetPostsByTagAsync(string tag); + void ClearCache(); } diff --git a/JoshHeaps.Net/appsettings.json b/JoshHeaps.Net/appsettings.json index be6b317..90f577d 100644 --- a/JoshHeaps.Net/appsettings.json +++ b/JoshHeaps.Net/appsettings.json @@ -7,6 +7,7 @@ }, "AllowedHosts": "*", "BlogApi": { - "BaseUrl": "https://media.joshheaps.net" + "BaseUrl": "https://media.joshheaps.net", + "InvalidateKey": "CHANGE_ME" } }