elastic / elastic/docs-builder
chore: Replace hand-rolled code with BCL/stdlib equivalents
- Dominant language
- C#
- Stars
- 24
- Forks
- 44
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 146
Description
## What
Several places in the codebase hand-roll logic the .NET BCL already ships. Replace them.
## Changes
### `InMemoryDistributedCache` → `MemoryDistributedCache`
The entire class (`src/api/Elastic.Documentation.Api/Caching/InMemoryDistributedCache.cs`, ~57 lines) hand-rolls `ConcurrentDictionary` + manual TTL expiry. `Microsoft.Extensions.Caching.Memory.MemoryDistributedCache` provides this with built-in absolute-expiration eviction.
Delete the file. Register `services.AddDistributedMemoryCache()` in DI.
### `MultiLayerCache` L1 layer → `IMemoryCache`
`src/api/Elastic.Documentation.Api/Caching/MultiLayerCache.cs` has a static `ConcurrentDictionary` + `TryGetFromL1`/`PopulateL1`/`IsExpired` (~40 lines) that duplicates `IMemoryCache` with absolute expiration. Keep the L2 decorator layer; back L1 with an injected `IMemoryCache`.
### `AppliesTo` ToString cluster → `string.Join`
Five methods across the applicability types all reimplement `string.Join` with a manual `hasContent` flag + repeated separator appends — one has a separator copy-paste bug (`": not null } => "` instead of `", "`):
- `ProductApplicability.ToString` — `src/Elastic.Documentation/AppliesTo/ProductApplicability.cs:84-127`
- `ApplicableTo.ToString` — `src/Elastic.Documentation/AppliesTo/ApplicableTo.cs:150-193`
- `DeploymentApplicability.ToString` — `src/Elastic.Documentation/AppliesTo/ApplicableTo.cs:214-250`
- `ServerlessProjectApplicability.ToString` — `src/Elastic.Documentation/AppliesTo/ApplicableTo.cs:277-303`
- `AppliesCollection.ToString` — `src/Elastic.Documentation/AppliesTo/Applicability.cs:152-164`
Replace each with: `string.Join(", ", parts.Where(p => p != null))` over a collected list.
### `StaticFileContentHashProvider` memoization → `GetOrAdd`
`src/Elastic.Documentation.Site/FileProviders/StaticFileContentHashProvider.cs:13-28` uses `TryGetValue` + assign. Replace with `_contentHashes.GetOrAdd(path, ComputeHash)`.
~170 lines → ~25 lines total across all changes.
Part of the broader ponytail over-engineering audit tracked in #3574.
Contributor guide
Assessment
This issue has not been assessed yet.