How dev-hive-school/typescript-lru-cache works
This project is not a full-stack app. It is a NestJS backend sample focused on one production-style concern: how to use lru-cache correctly for caching user permissions.
• NestJS application bootstrap
• module-based request handling
• permissions API
• cache layer
• permission data source / storage layer
• tests validating cache behavior
What this project is
• a TypeScript / NestJS application
• demonstrating best practices for LRU cache usage
• specifically in a permissions lookup flow
• with explicit invalidation, fixed TTL, and bounded memory usage
Instead, it should look like a single backend service with internal layers.
Client / API Consumer
• Represents whoever calls the permissions endpoint.
• Could be a browser, another backend service, or a CLI client.
NestJS Application Bootstrap
• src/main.ts
• Starts the server and wires the app together.
App Module
• src/app.module.ts
• Root composition module.
App Controller / App Service
• src/app.controller.ts
• src/app.service.ts
• Likely a basic root endpoint / app-level example.
Permissions Module
• src/permissions/permissions.module.ts
• Feature module for the cache-backed permissions logic.
Permissions Controller
• src/permissions/permissions.controller.ts
• HTTP interface for permissions operations.
Permissions Service
• src/permissions/permissions.service.ts
• Core business logic:
• reads permissions
• consults cache
• fetches from source of truth on miss
• invalidates cache when needed
LRU Cache
• This is the key architectural element.
• It explicitly as a separate component.
• It with:
• bounded entries (max)
• bounded size (maxSize)
• fixed TTL
• no refresh on read (updateAgeOnGet: false)
Permissions Storage / Source of Truth
• src/storage.ts
• This appears to be the backing data source for permissions.
• It may be an in-memory store or data access abstraction.
Unit Tests
• src/*.spec.ts
• src/permissions/*.spec.ts
E2E Tests
• test/app.e2e-spec.ts
These should usually be shown in a separate “Testing” lane or a side annotation, not in the main runtime path.
Service checks the LRU cache
• if cache hit: return cached permissions immediately
• if cache miss: fetch from storage.ts
Invalidation flow
There are two explicit invalidation operations mentioned in the README:
• invalidateUserPermissions(userId)
• clearPermissionsCache()
• targeted eviction for one user
• full cache clear for all users
This is an important part of the design and should be visually highlighted.
Architectural pattern to emphasize
This project uses a very clear NestJS modular layered architecture:
Pattern
• Controller layer
• handles HTTP requests/responses
• Service layer
• contains business logic and cache logic
• Data source layer
• storage.ts
• Cross-cutting cache layer
• lru-cache
Design principles
• Separation of concerns
• Dependency injection
• Feature-module organization
• Explicit cache invalidation
• Bounded memory cache
• Production-style TTL behavior
What to label
Be very explicit. Use labels like:
• NestJS App Entry Point
• Root Module
• Permissions Feature Module
• HTTP Controller
• Permissions Service
• LRU Cache
• max
• maxSize
• TTL
• updateAgeOnGet: false
• Permissions Source of Truth
• Cache Invalidation API
• invalidateUserPermissions(userId)
• clearPermissionsCache()
• bounded memory
• stale permissions revalidated on TTL expiry
• reads do not extend lifespan
Include:
• module boundaries
• cache boundary
• invalidation flow
• cache miss / hit paths
• source-of-truth storage
• test layer
But keep the runtime architecture focused.
Do not add unrelated infrastructure like:
• databases
• queues
• auth providers
• CDNs
• microservices
unless they are actually in the codebase, which they are not.
What technologies to mention
Major technologies because they define the architecture:
• NestJS
• TypeScript
• lru-cache
• Jest for tests
• Node.js runtime
Optional tooling to show as secondary:
• ESLint
• Prettier
• Nest CLI
Unit tests
• app.controller.spec.ts
• app.service.spec.ts
• permissions.controller.spec.ts
• permissions.service.spec.ts
E2E tests
• test/app.e2e-spec.ts
Tests as:
• validating controller/service behavior
• verifying real cache semantics:
• cache hits
• expiry
• invalidation
This is especially important because the README emphasizes that tests verify real cache behavior, not just mocks.
• separate controller, service, cache, and storage
• Read and invalidation paths
• make cache semantics explicit
• Tests as a supporting layer