Nomad changes
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s

This commit is contained in:
Henrik Jess Nielsen
2026-06-01 23:40:55 +02:00
parent 72b1a0a6ed
commit b4c07d3693
5723 changed files with 1130655 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
using Kreuzberg;
using System.Collections.Generic;
class CustomCacheBackend
{
private Dictionary<string, ExtractionResult> _cache = new();
public async Task<ExtractionResult> GetOrExtractAsync(
string filePath,
ExtractionConfig config)
{
var cacheKey = GenerateCacheKey(filePath, config);
if (_cache.TryGetValue(cacheKey, out var cachedResult))
{
Console.WriteLine("Using cached result");
return cachedResult;
}
var result = await KreuzbergLib.ExtractFileAsync(filePath, config);
_cache[cacheKey] = result;
Console.WriteLine("Result cached");
return result;
}
private string GenerateCacheKey(string filePath, ExtractionConfig config)
{
var configHash = config.ToString().GetHashCode();
return $"{filePath}:{configHash}";
}
public void ClearCache()
{
_cache.Clear();
Console.WriteLine("Cache cleared");
}
}
class Program
{
static async Task Main()
{
var cacheBackend = new CustomCacheBackend();
var config = new ExtractionConfig { UseCache = true };
try
{
var result1 = await cacheBackend.GetOrExtractAsync("document.pdf", config);
Console.WriteLine($"Result 1: {result1.Content.Length} chars");
var result2 = await cacheBackend.GetOrExtractAsync("document.pdf", config);
Console.WriteLine($"Result 2: {result2.Content.Length} chars");
cacheBackend.ClearCache();
}
catch (KreuzbergException ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}