Merge: Knowledge caching layer (closes #79)

This commit is contained in:
Jason Woltje
2026-01-30 00:16:36 -06:00
13 changed files with 1522 additions and 388 deletions

View File

@@ -19,6 +19,7 @@ import { WorkspaceGuard, PermissionGuard } from "../common/guards";
import { Workspace, Permission, RequirePermission } from "../common/decorators";
import { CurrentUser } from "../auth/decorators/current-user.decorator";
import { LinkSyncService } from "./services/link-sync.service";
import { KnowledgeCacheService } from "./services/cache.service";
/**
* Controller for knowledge entry endpoints
@@ -190,3 +191,50 @@ export class KnowledgeController {
);
}
}
/**
* Controller for knowledge cache endpoints
*/
@Controller("knowledge/cache")
@UseGuards(AuthGuard, WorkspaceGuard, PermissionGuard)
export class KnowledgeCacheController {
constructor(private readonly cache: KnowledgeCacheService) {}
/**
* GET /api/knowledge/cache/stats
* Get cache statistics (hits, misses, hit rate, etc.)
* Requires: Any workspace member
*/
@Get("stats")
@RequirePermission(Permission.WORKSPACE_ANY)
async getStats() {
return {
enabled: this.cache.isEnabled(),
stats: this.cache.getStats(),
};
}
/**
* POST /api/knowledge/cache/clear
* Clear all caches for the workspace
* Requires: ADMIN role or higher
*/
@Post("clear")
@RequirePermission(Permission.WORKSPACE_ADMIN)
async clearCache(@Workspace() workspaceId: string) {
await this.cache.clearWorkspaceCache(workspaceId);
return { message: "Cache cleared successfully" };
}
/**
* POST /api/knowledge/cache/stats/reset
* Reset cache statistics
* Requires: ADMIN role or higher
*/
@Post("stats/reset")
@RequirePermission(Permission.WORKSPACE_ADMIN)
async resetStats() {
this.cache.resetStats();
return { message: "Cache statistics reset successfully" };
}
}