@nest-omni/core 4.1.3-2 → 4.1.3-20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/audit/audit.module.d.ts +10 -0
- package/audit/audit.module.js +63 -1
- package/audit/controllers/audit.controller.d.ts +88 -0
- package/audit/controllers/audit.controller.js +74 -0
- package/audit/decorators/audit-action.decorator.d.ts +74 -0
- package/audit/decorators/audit-action.decorator.js +42 -0
- package/audit/decorators/audit-controller.decorator.d.ts +9 -1
- package/audit/decorators/audit-controller.decorator.js +11 -2
- package/audit/decorators/audit-operation.decorator.d.ts +45 -0
- package/audit/decorators/audit-operation.decorator.js +49 -0
- package/audit/decorators/entity-audit.decorator.d.ts +85 -1
- package/audit/decorators/entity-audit.decorator.js +153 -3
- package/audit/decorators/index.d.ts +2 -0
- package/audit/decorators/index.js +2 -0
- package/audit/dto/audit-log-query.dto.d.ts +3 -0
- package/audit/dto/audit-log-query.dto.js +3 -0
- package/audit/dto/begin-transaction.dto.d.ts +3 -0
- package/audit/dto/begin-transaction.dto.js +3 -0
- package/audit/dto/compare-entities.dto.d.ts +3 -0
- package/audit/dto/compare-entities.dto.js +3 -0
- package/audit/dto/pre-check-restore.dto.d.ts +3 -0
- package/audit/dto/pre-check-restore.dto.js +3 -0
- package/audit/dto/restore-entity.dto.d.ts +3 -0
- package/audit/dto/restore-entity.dto.js +3 -0
- package/audit/entities/audit-action-summary.entity.d.ts +23 -0
- package/audit/entities/audit-action-summary.entity.js +101 -0
- package/audit/entities/entity-audit-log.entity.d.ts +11 -0
- package/audit/entities/entity-audit-log.entity.js +57 -2
- package/audit/entities/entity-transaction.entity.d.ts +11 -2
- package/audit/entities/entity-transaction.entity.js +42 -3
- package/audit/entities/index.d.ts +3 -0
- package/audit/entities/index.js +3 -0
- package/audit/entities/manual-operation-log.entity.d.ts +4 -0
- package/audit/entities/manual-operation-log.entity.js +12 -1
- package/audit/entities/operation-template.entity.d.ts +4 -0
- package/audit/entities/operation-template.entity.js +4 -0
- package/audit/enums/audit.enums.d.ts +37 -6
- package/audit/enums/audit.enums.js +40 -7
- package/audit/index.d.ts +4 -1
- package/audit/index.js +34 -1
- package/audit/interceptors/audit-action.interceptor.d.ts +38 -0
- package/audit/interceptors/audit-action.interceptor.js +215 -0
- package/audit/interceptors/audit.interceptor.d.ts +15 -0
- package/audit/interceptors/audit.interceptor.js +23 -1
- package/audit/interceptors/index.d.ts +1 -0
- package/audit/interceptors/index.js +1 -0
- package/audit/interfaces/audit.interfaces.d.ts +187 -2
- package/audit/services/audit-action.service.d.ts +141 -0
- package/audit/services/audit-action.service.js +244 -0
- package/audit/services/audit-context.service.d.ts +97 -0
- package/audit/services/audit-context.service.js +185 -0
- package/audit/services/audit-strategy.service.d.ts +6 -0
- package/audit/services/audit-strategy.service.js +13 -0
- package/audit/services/entity-audit.service.d.ts +230 -3
- package/audit/services/entity-audit.service.js +607 -14
- package/audit/services/index.d.ts +3 -0
- package/audit/services/index.js +3 -0
- package/audit/services/manual-audit-log.service.d.ts +134 -9
- package/audit/services/manual-audit-log.service.js +157 -40
- package/audit/services/multi-database.service.d.ts +9 -2
- package/audit/services/multi-database.service.js +9 -21
- package/audit/services/operation-description.service.d.ts +71 -2
- package/audit/services/operation-description.service.js +231 -20
- package/audit/services/transaction-audit.service.d.ts +30 -0
- package/audit/services/transaction-audit.service.js +53 -5
- package/audit/subscribers/entity-audit.subscriber.d.ts +19 -0
- package/audit/subscribers/entity-audit.subscriber.js +76 -1
- package/cache/cache-metrics.service.d.ts +67 -0
- package/cache/cache-metrics.service.js +68 -4
- package/cache/cache-serialization.service.d.ts +31 -0
- package/cache/cache-serialization.service.js +25 -0
- package/cache/cache.constants.d.ts +9 -0
- package/cache/cache.constants.js +9 -0
- package/cache/cache.health.d.ts +26 -0
- package/cache/cache.health.js +30 -0
- package/cache/cache.module.d.ts +82 -2
- package/cache/cache.module.js +76 -5
- package/cache/cache.service.d.ts +140 -0
- package/cache/cache.service.js +169 -0
- package/cache/cache.warmup.service.d.ts +39 -0
- package/cache/cache.warmup.service.js +32 -0
- package/cache/decorators/cache-evict.decorator.d.ts +47 -0
- package/cache/decorators/cache-evict.decorator.js +56 -0
- package/cache/decorators/cache-put.decorator.d.ts +34 -0
- package/cache/decorators/cache-put.decorator.js +39 -0
- package/cache/decorators/cacheable.decorator.d.ts +40 -0
- package/cache/decorators/cacheable.decorator.js +55 -0
- package/cache/dependencies/callback.dependency.d.ts +33 -0
- package/cache/dependencies/callback.dependency.js +39 -1
- package/cache/dependencies/chain.dependency.d.ts +28 -0
- package/cache/dependencies/chain.dependency.js +34 -0
- package/cache/dependencies/db.dependency.d.ts +83 -7
- package/cache/dependencies/db.dependency.js +89 -14
- package/cache/dependencies/file.dependency.d.ts +32 -0
- package/cache/dependencies/file.dependency.js +34 -0
- package/cache/dependencies/tag.dependency.d.ts +75 -4
- package/cache/dependencies/tag.dependency.js +145 -11
- package/cache/dependencies/time.dependency.d.ts +43 -0
- package/cache/dependencies/time.dependency.js +43 -0
- package/cache/examples/basic-usage.d.ts +15 -0
- package/cache/examples/basic-usage.js +62 -8
- package/cache/index.js +9 -0
- package/cache/interfaces/cache-dependency.interface.d.ts +53 -0
- package/cache/interfaces/cache-options.interface.d.ts +89 -0
- package/cache/interfaces/cache-options.interface.js +6 -0
- package/cache/interfaces/cache-provider.interface.d.ts +78 -0
- package/cache/providers/base-cache.provider.d.ts +14 -0
- package/cache/providers/base-cache.provider.js +16 -0
- package/cache/providers/cls-cache.provider.d.ts +20 -0
- package/cache/providers/cls-cache.provider.js +28 -0
- package/cache/providers/memory-cache.provider.d.ts +43 -0
- package/cache/providers/memory-cache.provider.js +66 -0
- package/cache/providers/redis-cache.provider.d.ts +26 -0
- package/cache/providers/redis-cache.provider.js +29 -0
- package/cache/utils/dependency-manager.util.d.ts +52 -0
- package/cache/utils/dependency-manager.util.js +59 -0
- package/cache/utils/key-generator.util.d.ts +42 -0
- package/cache/utils/key-generator.util.js +53 -1
- package/common/abstract.entity.d.ts +14 -0
- package/common/abstract.entity.js +14 -0
- package/common/boilerplate.polyfill.d.ts +142 -0
- package/common/boilerplate.polyfill.js +18 -1
- package/common/dto/dto-container.d.ts +16 -0
- package/common/dto/dto-container.js +20 -0
- package/common/dto/dto-decorators.d.ts +18 -0
- package/common/dto/dto-decorators.js +14 -0
- package/common/dto/dto-extensions.d.ts +11 -0
- package/common/dto/dto-extensions.js +9 -0
- package/common/dto/dto-service-accessor.d.ts +17 -0
- package/common/dto/dto-service-accessor.js +18 -0
- package/common/dto/dto-transformer.d.ts +12 -0
- package/common/dto/dto-transformer.js +9 -0
- package/common/dto/index.js +2 -0
- package/common/examples/paginate-and-map.example.d.ts +6 -0
- package/common/examples/paginate-and-map.example.js +26 -0
- package/common/utils.d.ts +15 -0
- package/common/utils.js +15 -0
- package/constants/language-code.js +1 -0
- package/decorators/field.decorators.d.ts +1 -1
- package/decorators/field.decorators.js +8 -1
- package/decorators/property.decorators.js +1 -0
- package/decorators/public-route.decorator.js +1 -0
- package/decorators/transform.decorators.d.ts +27 -0
- package/decorators/transform.decorators.js +29 -0
- package/decorators/translate.decorator.js +1 -0
- package/decorators/user.decorator.js +1 -0
- package/decorators/validator.decorators.d.ts +8 -18
- package/decorators/validator.decorators.js +22 -190
- package/file-upload/controllers/file-access.controller.d.ts +23 -0
- package/file-upload/controllers/file-access.controller.js +128 -0
- package/file-upload/decorators/column.decorator.d.ts +151 -0
- package/file-upload/decorators/column.decorator.js +273 -0
- package/file-upload/decorators/csv-data.decorator.d.ts +30 -0
- package/file-upload/decorators/csv-data.decorator.js +85 -0
- package/file-upload/decorators/csv-import.decorator.d.ts +34 -0
- package/file-upload/decorators/csv-import.decorator.js +24 -0
- package/file-upload/decorators/examples/column-mapping.example.d.ts +76 -0
- package/file-upload/decorators/examples/column-mapping.example.js +122 -0
- package/file-upload/decorators/excel-data.decorator.d.ts +30 -0
- package/file-upload/decorators/excel-data.decorator.js +85 -0
- package/file-upload/decorators/file-upload.decorator.d.ts +83 -0
- package/file-upload/decorators/file-upload.decorator.js +172 -0
- package/file-upload/decorators/index.d.ts +5 -0
- package/file-upload/decorators/index.js +38 -0
- package/file-upload/decorators/process.decorator.d.ts +40 -0
- package/file-upload/decorators/process.decorator.js +52 -0
- package/file-upload/decorators/validate-data.decorator.d.ts +91 -0
- package/file-upload/decorators/validate-data.decorator.js +39 -0
- package/file-upload/dto/create-file.dto.d.ts +24 -0
- package/file-upload/dto/create-file.dto.js +112 -0
- package/file-upload/dto/find-files.dto.d.ts +15 -0
- package/file-upload/dto/find-files.dto.js +76 -0
- package/file-upload/dto/index.d.ts +4 -0
- package/file-upload/dto/index.js +20 -0
- package/file-upload/dto/pagination.dto.d.ts +7 -0
- package/file-upload/dto/pagination.dto.js +39 -0
- package/file-upload/dto/update-file.dto.d.ts +15 -0
- package/file-upload/dto/update-file.dto.js +67 -0
- package/file-upload/entities/file-metadata.entity.d.ts +25 -0
- package/file-upload/entities/file-metadata.entity.js +76 -0
- package/file-upload/entities/file.entity.d.ts +114 -0
- package/file-upload/entities/file.entity.js +350 -0
- package/file-upload/entities/index.d.ts +2 -0
- package/file-upload/entities/index.js +18 -0
- package/file-upload/enums/file-type.enum.d.ts +72 -0
- package/file-upload/enums/file-type.enum.js +212 -0
- package/file-upload/exceptions/file-upload.exception.d.ts +57 -0
- package/file-upload/exceptions/file-upload.exception.js +120 -0
- package/file-upload/exceptions/index.d.ts +1 -0
- package/file-upload/exceptions/index.js +17 -0
- package/file-upload/file-upload.module.d.ts +89 -0
- package/file-upload/file-upload.module.js +292 -0
- package/file-upload/index.d.ts +37 -0
- package/file-upload/index.js +77 -0
- package/file-upload/interceptors/file-upload.interceptor.d.ts +101 -0
- package/file-upload/interceptors/file-upload.interceptor.js +594 -0
- package/file-upload/interceptors/index.d.ts +1 -0
- package/file-upload/interceptors/index.js +17 -0
- package/file-upload/interfaces/custom-file-type.interface.d.ts +72 -0
- package/file-upload/interfaces/custom-file-type.interface.js +2 -0
- package/file-upload/interfaces/file-buffer.interface.d.ts +72 -0
- package/file-upload/interfaces/file-buffer.interface.js +2 -0
- package/file-upload/interfaces/file-entity.interface.d.ts +142 -0
- package/file-upload/interfaces/file-entity.interface.js +28 -0
- package/file-upload/interfaces/file-metadata.interface.d.ts +21 -0
- package/file-upload/interfaces/file-metadata.interface.js +2 -0
- package/file-upload/interfaces/file-processor.interface.d.ts +93 -0
- package/file-upload/interfaces/file-processor.interface.js +2 -0
- package/file-upload/interfaces/file-upload-options.interface.d.ts +74 -0
- package/file-upload/interfaces/file-upload-options.interface.js +5 -0
- package/file-upload/interfaces/index.d.ts +7 -0
- package/file-upload/interfaces/index.js +24 -0
- package/file-upload/interfaces/processor-options.interface.d.ts +102 -0
- package/file-upload/interfaces/processor-options.interface.js +2 -0
- package/file-upload/interfaces/storage-provider.interface.d.ts +239 -0
- package/file-upload/interfaces/storage-provider.interface.js +2 -0
- package/file-upload/interfaces/upload-options.interface.d.ts +19 -0
- package/file-upload/interfaces/upload-options.interface.js +2 -0
- package/file-upload/processors/csv.processor.d.ts +98 -0
- package/file-upload/processors/csv.processor.js +391 -0
- package/file-upload/processors/excel.processor.d.ts +130 -0
- package/file-upload/processors/excel.processor.js +547 -0
- package/file-upload/processors/image.processor.d.ts +199 -0
- package/file-upload/processors/image.processor.js +377 -0
- package/file-upload/providers/index.d.ts +2 -0
- package/file-upload/providers/index.js +18 -0
- package/file-upload/providers/local-storage.provider.d.ts +98 -0
- package/file-upload/providers/local-storage.provider.js +484 -0
- package/file-upload/providers/s3-storage.provider.d.ts +87 -0
- package/file-upload/providers/s3-storage.provider.js +455 -0
- package/file-upload/services/file-signature-validator.service.d.ts +118 -0
- package/file-upload/services/file-signature-validator.service.js +376 -0
- package/file-upload/services/file.service.d.ts +193 -0
- package/file-upload/services/file.service.js +638 -0
- package/file-upload/services/index.d.ts +4 -0
- package/file-upload/services/index.js +20 -0
- package/file-upload/services/malicious-file-detector.service.d.ts +300 -0
- package/file-upload/services/malicious-file-detector.service.js +1234 -0
- package/file-upload/services/mime-registry.service.d.ts +47 -0
- package/file-upload/services/mime-registry.service.js +167 -0
- package/file-upload/utils/checksum.util.d.ts +28 -0
- package/file-upload/utils/checksum.util.js +65 -0
- package/file-upload/utils/dynamic-import.util.d.ts +54 -0
- package/file-upload/utils/dynamic-import.util.js +156 -0
- package/file-upload/utils/filename.util.d.ts +59 -0
- package/file-upload/utils/filename.util.js +184 -0
- package/file-upload/utils/filepath.util.d.ts +70 -0
- package/file-upload/utils/filepath.util.js +152 -0
- package/file-upload/utils/index.d.ts +4 -0
- package/file-upload/utils/index.js +20 -0
- package/filters/constraint-errors.js +1 -0
- package/helpers/common.helper.d.ts +13 -0
- package/helpers/common.helper.js +13 -0
- package/http-client/config/http-client.config.d.ts +20 -0
- package/http-client/config/http-client.config.js +48 -21
- package/http-client/decorators/http-client.decorators.d.ts +55 -14
- package/http-client/decorators/http-client.decorators.js +154 -78
- package/http-client/entities/http-log.entity.d.ts +217 -8
- package/http-client/entities/http-log.entity.js +7 -22
- package/http-client/errors/http-client.errors.d.ts +57 -0
- package/http-client/errors/http-client.errors.js +58 -0
- package/http-client/examples/advanced-usage.example.d.ts +40 -0
- package/http-client/examples/advanced-usage.example.js +53 -61
- package/http-client/examples/auth-with-waiting-lock.example.d.ts +31 -0
- package/http-client/examples/auth-with-waiting-lock.example.js +52 -5
- package/http-client/examples/basic-usage.example.d.ts +60 -0
- package/http-client/examples/basic-usage.example.js +60 -0
- package/http-client/examples/multi-api-configuration.example.d.ts +60 -0
- package/http-client/examples/multi-api-configuration.example.js +76 -5
- package/http-client/examples/proxy-from-environment.example.d.ts +133 -0
- package/http-client/examples/proxy-from-environment.example.js +409 -0
- package/http-client/http-client.module.d.ts +48 -2
- package/http-client/http-client.module.js +147 -68
- package/http-client/index.d.ts +1 -1
- package/http-client/index.js +8 -0
- package/http-client/interfaces/api-client-config.interface.d.ts +80 -45
- package/http-client/interfaces/api-client-config.interface.js +3 -0
- package/http-client/interfaces/http-client-config.interface.d.ts +109 -52
- package/http-client/services/api-client-registry.service.d.ts +50 -11
- package/http-client/services/api-client-registry.service.js +90 -250
- package/http-client/services/circuit-breaker.service.d.ts +115 -2
- package/http-client/services/circuit-breaker.service.js +237 -7
- package/http-client/services/http-client.service.d.ts +124 -14
- package/http-client/services/http-client.service.js +437 -148
- package/http-client/services/http-log-query.service.d.ts +83 -0
- package/http-client/services/http-log-query.service.js +121 -13
- package/http-client/services/http-replay.service.d.ts +101 -0
- package/http-client/services/http-replay.service.js +86 -0
- package/http-client/services/index.d.ts +0 -1
- package/http-client/services/index.js +0 -1
- package/http-client/services/log-cleanup.service.d.ts +63 -0
- package/http-client/services/log-cleanup.service.js +54 -2
- package/http-client/services/logging.service.d.ts +116 -7
- package/http-client/services/logging.service.js +349 -86
- package/http-client/utils/call-stack-extractor.util.d.ts +63 -0
- package/http-client/utils/call-stack-extractor.util.js +83 -0
- package/http-client/utils/context-extractor.util.d.ts +49 -0
- package/http-client/utils/context-extractor.util.js +52 -0
- package/http-client/utils/curl-generator.util.d.ts +21 -0
- package/http-client/utils/curl-generator.util.js +44 -3
- package/http-client/utils/index.d.ts +1 -0
- package/http-client/utils/index.js +1 -0
- package/http-client/utils/proxy-environment.util.d.ts +42 -0
- package/http-client/utils/proxy-environment.util.js +148 -0
- package/http-client/utils/request-id.util.d.ts +18 -0
- package/http-client/utils/request-id.util.js +20 -0
- package/http-client/utils/retry-recorder.util.d.ts +42 -0
- package/http-client/utils/retry-recorder.util.js +44 -0
- package/http-client/utils/security-validator.util.d.ts +118 -0
- package/http-client/utils/security-validator.util.js +352 -0
- package/index.d.ts +3 -1
- package/index.js +12 -1
- package/interceptors/translation-interceptor.service.js +5 -0
- package/package.json +11 -7
- package/providers/context.provider.js +2 -0
- package/providers/generator.provider.d.ts +4 -0
- package/providers/generator.provider.js +4 -0
- package/redis-lock/comprehensive-lock-cleanup.service.d.ts +94 -0
- package/redis-lock/comprehensive-lock-cleanup.service.js +253 -0
- package/redis-lock/examples/lock-strategy.examples.d.ts +89 -0
- package/redis-lock/examples/lock-strategy.examples.js +130 -15
- package/redis-lock/index.d.ts +2 -0
- package/redis-lock/index.js +8 -1
- package/redis-lock/lock-heartbeat.service.d.ts +80 -0
- package/redis-lock/lock-heartbeat.service.js +232 -0
- package/redis-lock/redis-lock.decorator.d.ts +101 -0
- package/redis-lock/redis-lock.decorator.js +120 -0
- package/redis-lock/redis-lock.module.d.ts +66 -0
- package/redis-lock/redis-lock.module.js +175 -70
- package/redis-lock/redis-lock.service.d.ts +282 -0
- package/redis-lock/redis-lock.service.js +343 -20
- package/setup/bootstrap.setup.d.ts +1 -0
- package/setup/bootstrap.setup.js +21 -0
- package/setup/index.d.ts +1 -0
- package/setup/index.js +1 -0
- package/setup/mode.setup.d.ts +44 -0
- package/setup/mode.setup.js +44 -0
- package/setup/run-in-mode.decorator.d.ts +56 -0
- package/setup/run-in-mode.decorator.js +92 -0
- package/setup/schedule.decorator.d.ts +227 -0
- package/setup/schedule.decorator.js +240 -12
- package/setup/worker.decorator.d.ts +86 -0
- package/setup/worker.decorator.js +97 -0
- package/shared/index.d.ts +1 -1
- package/shared/index.js +1 -1
- package/shared/{serviceRegistryModule.js → service-registry.module.js} +19 -17
- package/shared/services/api-config.service.d.ts +3 -0
- package/shared/services/api-config.service.js +21 -9
- package/shared/services/index.d.ts +0 -1
- package/shared/services/index.js +0 -1
- package/validator-json/decorators.d.ts +17 -0
- package/validator-json/decorators.js +17 -2
- package/validator-json/default.d.ts +6 -0
- package/validator-json/default.js +30 -2
- package/validator-json/defaultConverters.js +1 -0
- package/validator-json/options.d.ts +23 -0
- package/validators/common-validators.d.ts +143 -0
- package/validators/common-validators.js +249 -0
- package/validators/custom-validate.examples.d.ts +23 -0
- package/validators/custom-validate.examples.js +78 -6
- package/validators/custom-validate.validator.d.ts +108 -0
- package/validators/custom-validate.validator.js +85 -0
- package/validators/file-mimetype.validator.d.ts +0 -2
- package/validators/file-mimetype.validator.js +4 -6
- package/validators/index.d.ts +1 -0
- package/validators/index.js +1 -0
- package/validators/is-exists.validator.d.ts +26 -6
- package/validators/is-exists.validator.js +30 -7
- package/validators/is-unique.validator.d.ts +33 -7
- package/validators/is-unique.validator.js +59 -17
- package/validators/skip-empty.validator.d.ts +5 -0
- package/validators/skip-empty.validator.js +5 -0
- package/vault/interfaces/vault-options.interface.d.ts +9 -0
- package/vault/vault-config.loader.d.ts +30 -0
- package/vault/vault-config.loader.js +48 -1
- package/vault/vault-config.service.d.ts +53 -0
- package/vault/vault-config.service.js +57 -0
- package/vault/vault.module.d.ts +4 -0
- package/vault/vault.module.js +4 -0
- package/decorators/examples/validation-decorators.example.d.ts +0 -69
- package/decorators/examples/validation-decorators.example.js +0 -331
- package/http-client/services/cache.service.d.ts +0 -24
- package/http-client/services/cache.service.js +0 -264
- package/shared/services/validator.service.d.ts +0 -3
- package/shared/services/validator.service.js +0 -20
- /package/shared/{serviceRegistryModule.d.ts → service-registry.module.d.ts} +0 -0
package/cache/cache.service.js
CHANGED
|
@@ -30,6 +30,15 @@ const providers_1 = require("./providers");
|
|
|
30
30
|
const utils_1 = require("./utils");
|
|
31
31
|
const cache_serialization_service_1 = require("./cache-serialization.service");
|
|
32
32
|
const cache_constants_1 = require("./cache.constants");
|
|
33
|
+
/**
|
|
34
|
+
* Unified cache service with three-tier architecture
|
|
35
|
+
*
|
|
36
|
+
* L1: CLS (request-level)
|
|
37
|
+
* L2: Memory (process-level)
|
|
38
|
+
* L3: Redis (distributed)
|
|
39
|
+
*
|
|
40
|
+
* Supports automatic fallback, backfill, and dependency-based invalidation.
|
|
41
|
+
*/
|
|
33
42
|
let CacheService = CacheService_1 = class CacheService {
|
|
34
43
|
constructor(clsProvider, memoryProvider, redisProvider, enableCompression = false, compressionThreshold = 1024) {
|
|
35
44
|
this.clsProvider = clsProvider;
|
|
@@ -54,22 +63,54 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
54
63
|
this.providers.set(interfaces_1.CacheLayer.REDIS, redisProvider);
|
|
55
64
|
this.initializeStats();
|
|
56
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Get or set cache value with factory function
|
|
68
|
+
*
|
|
69
|
+
* @param key - Cache key
|
|
70
|
+
* @param factory - Function to generate value if not cached
|
|
71
|
+
* @param options - Cache options
|
|
72
|
+
* @returns Cached or generated value
|
|
73
|
+
*/
|
|
57
74
|
getOrSet(key, factory, options) {
|
|
58
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
// Try to get from cache
|
|
59
77
|
const cached = yield this.get(key, options);
|
|
60
78
|
if (cached !== null) {
|
|
61
79
|
return cached;
|
|
62
80
|
}
|
|
81
|
+
// Generate new value
|
|
63
82
|
const value = yield factory();
|
|
83
|
+
// Cache the value
|
|
64
84
|
yield this.set(key, value, options);
|
|
65
85
|
return value;
|
|
66
86
|
});
|
|
67
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Get value from cache with optional layer specification
|
|
90
|
+
*
|
|
91
|
+
* @param key - Cache key
|
|
92
|
+
* @param options - Cache options including layer preference
|
|
93
|
+
* @returns Cached value or null
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* // Try memory only
|
|
98
|
+
* const data = await this.cacheService.get('user:123', {
|
|
99
|
+
* layers: [CacheLayer.MEMORY]
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* // Try all layers in order (CLS -> MEMORY -> REDIS)
|
|
103
|
+
* const data = await this.cacheService.get('config:app', {
|
|
104
|
+
* layers: [CacheLayer.CLS, CacheLayer.MEMORY, CacheLayer.REDIS]
|
|
105
|
+
* });
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
68
108
|
get(key, options) {
|
|
69
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
110
|
this.stats.totalGets++;
|
|
71
111
|
const layers = this.resolveLayers(options === null || options === void 0 ? void 0 : options.layers);
|
|
72
112
|
const fullKey = this.buildKey(key, options === null || options === void 0 ? void 0 : options.namespace);
|
|
113
|
+
// Try each layer in order
|
|
73
114
|
for (let i = 0; i < layers.length; i++) {
|
|
74
115
|
const layer = layers[i];
|
|
75
116
|
const provider = this.providers.get(layer);
|
|
@@ -79,19 +120,24 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
79
120
|
try {
|
|
80
121
|
const wrapped = yield provider.get(fullKey);
|
|
81
122
|
if (wrapped !== null) {
|
|
123
|
+
// Validate dependencies if present
|
|
82
124
|
let value = yield utils_1.DependencyManager.unwrapAndValidate(wrapped, options === null || options === void 0 ? void 0 : options.dependencies);
|
|
83
125
|
if (value !== null) {
|
|
126
|
+
// Check if value is compressed and decompress if needed
|
|
84
127
|
if (this.enableCompression && Buffer.isBuffer(value)) {
|
|
85
128
|
const serializationService = new cache_serialization_service_1.CacheSerializationService();
|
|
86
129
|
const decompressed = yield serializationService.deserialize(value);
|
|
87
130
|
value = decompressed.data;
|
|
88
131
|
}
|
|
132
|
+
// Cache hit
|
|
89
133
|
this.recordHit(layer);
|
|
134
|
+
// Backfill upper layers
|
|
90
135
|
if ((options === null || options === void 0 ? void 0 : options.backfill) !== false && i > 0) {
|
|
91
136
|
yield this.backfillUpperLayers(fullKey, wrapped, layers.slice(0, i), options === null || options === void 0 ? void 0 : options.ttl);
|
|
92
137
|
}
|
|
93
138
|
return value;
|
|
94
139
|
}
|
|
140
|
+
// Dependencies changed, delete from this layer
|
|
95
141
|
yield provider.delete(fullKey);
|
|
96
142
|
}
|
|
97
143
|
}
|
|
@@ -99,20 +145,63 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
99
145
|
this.logger.warn(`Failed to get from ${layer} cache: ${error instanceof Error ? error.message : String(error)}`);
|
|
100
146
|
}
|
|
101
147
|
}
|
|
148
|
+
// Cache miss
|
|
102
149
|
this.recordMiss();
|
|
103
150
|
return null;
|
|
104
151
|
});
|
|
105
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Set value in cache with optional layer specification
|
|
155
|
+
*
|
|
156
|
+
* Supports both new API (CacheOptions) and legacy API (TTL number) for backward compatibility.
|
|
157
|
+
*
|
|
158
|
+
* @param key - Cache key
|
|
159
|
+
* @param value - Value to cache
|
|
160
|
+
* @param options - Cache options including layer selection OR TTL (number) for legacy compatibility
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* // New API - Cache in memory only
|
|
165
|
+
* await this.cacheService.set('user:123', userData, {
|
|
166
|
+
* layers: [CacheLayer.MEMORY],
|
|
167
|
+
* ttl: 300000
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* // Legacy API - TTL as third parameter (still works for backward compatibility)
|
|
171
|
+
* await this.cacheService.set('user:123', userData, 300000);
|
|
172
|
+
*
|
|
173
|
+
* // Cache in all layers (default behavior)
|
|
174
|
+
* await this.cacheService.set('config:app', configData, {
|
|
175
|
+
* layers: [CacheLayer.CLS, CacheLayer.MEMORY, CacheLayer.REDIS],
|
|
176
|
+
* ttl: 3600000
|
|
177
|
+
* });
|
|
178
|
+
*
|
|
179
|
+
* // Cache in Redis only (distributed)
|
|
180
|
+
* await this.cacheService.set('global:settings', settings, {
|
|
181
|
+
* layers: [CacheLayer.REDIS],
|
|
182
|
+
* ttl: 86400000
|
|
183
|
+
* });
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
106
186
|
set(key, value, options) {
|
|
107
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
// Check if the third parameter is a number (old API) or CacheOptions (new API)
|
|
108
189
|
if (typeof options === 'number') {
|
|
190
|
+
// Old cache-manager API: set(key, value, ttl)
|
|
109
191
|
return this.setWithOptions(key, value, { ttl: options });
|
|
110
192
|
}
|
|
111
193
|
else {
|
|
194
|
+
// New API: set(key, value, options)
|
|
112
195
|
return this.setWithOptions(key, value, options);
|
|
113
196
|
}
|
|
114
197
|
});
|
|
115
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Delete value from cache
|
|
201
|
+
*
|
|
202
|
+
* @param key - Cache key or array of keys
|
|
203
|
+
* @param layers - Specific layers to delete from (default: all)
|
|
204
|
+
*/
|
|
116
205
|
del(key, layers) {
|
|
117
206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
207
|
this.stats.totalDeletes++;
|
|
@@ -133,6 +222,12 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
133
222
|
yield Promise.all(promises);
|
|
134
223
|
});
|
|
135
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Delete keys matching pattern
|
|
227
|
+
*
|
|
228
|
+
* @param pattern - Pattern to match (e.g., 'user:*')
|
|
229
|
+
* @param layers - Specific layers to delete from (default: Memory and Redis only)
|
|
230
|
+
*/
|
|
136
231
|
deletePattern(pattern, layers) {
|
|
137
232
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
233
|
const targetLayers = layers || [interfaces_1.CacheLayer.MEMORY, interfaces_1.CacheLayer.REDIS];
|
|
@@ -151,6 +246,11 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
151
246
|
yield Promise.all(promises);
|
|
152
247
|
});
|
|
153
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Clear all cache
|
|
251
|
+
*
|
|
252
|
+
* @param layers - Specific layers to clear (default: all)
|
|
253
|
+
*/
|
|
154
254
|
clear(layers) {
|
|
155
255
|
return __awaiter(this, void 0, void 0, function* () {
|
|
156
256
|
this.stats.totalClears++;
|
|
@@ -170,27 +270,53 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
170
270
|
yield Promise.all(promises);
|
|
171
271
|
});
|
|
172
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* Invalidate tags (for TagDependency)
|
|
275
|
+
*
|
|
276
|
+
* @param tags - Tags to invalidate
|
|
277
|
+
*/
|
|
173
278
|
invalidateTags(tags) {
|
|
174
279
|
return __awaiter(this, void 0, void 0, function* () {
|
|
175
280
|
dependencies_1.TagDependency.invalidateTags(tags);
|
|
176
281
|
this.logger.debug(`Invalidated tags: ${tags.join(', ')}`);
|
|
177
282
|
});
|
|
178
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Get multiple values
|
|
286
|
+
*
|
|
287
|
+
* @param keys - Array of cache keys
|
|
288
|
+
* @param options - Cache options
|
|
289
|
+
* @returns Array of values (null for missing keys)
|
|
290
|
+
*/
|
|
179
291
|
mget(keys, options) {
|
|
180
292
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
293
|
const promises = keys.map((key) => this.get(key, options));
|
|
182
294
|
return Promise.all(promises);
|
|
183
295
|
});
|
|
184
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Set multiple values
|
|
299
|
+
*
|
|
300
|
+
* @param items - Array of key-value pairs
|
|
301
|
+
* @param options - Cache options
|
|
302
|
+
*/
|
|
185
303
|
mset(items, options) {
|
|
186
304
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
305
|
const promises = items.map((item) => this.set(item.key, item.value, options));
|
|
188
306
|
yield Promise.all(promises);
|
|
189
307
|
});
|
|
190
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Get cache statistics
|
|
311
|
+
*
|
|
312
|
+
* @returns Cache statistics
|
|
313
|
+
*/
|
|
191
314
|
getStats() {
|
|
192
315
|
return Object.assign(Object.assign({}, this.stats), { hitRate: this.stats.totalGets > 0 ? this.stats.hits / this.stats.totalGets : 0 });
|
|
193
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Reset statistics
|
|
319
|
+
*/
|
|
194
320
|
resetStats() {
|
|
195
321
|
this.stats.totalGets = 0;
|
|
196
322
|
this.stats.hits = 0;
|
|
@@ -201,14 +327,31 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
201
327
|
this.stats.totalClears = 0;
|
|
202
328
|
this.initializeStats();
|
|
203
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Internal method to set cache value with options
|
|
332
|
+
*/
|
|
204
333
|
setWithOptions(key, value, options) {
|
|
205
334
|
return __awaiter(this, void 0, void 0, function* () {
|
|
206
335
|
this.stats.totalSets++;
|
|
336
|
+
// Validate TTL if provided
|
|
337
|
+
if ((options === null || options === void 0 ? void 0 : options.ttl) !== undefined) {
|
|
338
|
+
if (typeof options.ttl !== 'number' || options.ttl < 0) {
|
|
339
|
+
this.logger.warn(`Invalid TTL value: ${options.ttl}. TTL must be a non-negative number. Using default behavior.`);
|
|
340
|
+
// Continue without TTL
|
|
341
|
+
options.ttl = undefined;
|
|
342
|
+
}
|
|
343
|
+
else if (options.ttl === 0) {
|
|
344
|
+
// TTL of 0 means no expiration
|
|
345
|
+
options.ttl = undefined;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
// Check condition
|
|
207
349
|
if ((options === null || options === void 0 ? void 0 : options.condition) && !(yield Promise.resolve(options.condition()))) {
|
|
208
350
|
return;
|
|
209
351
|
}
|
|
210
352
|
const layers = this.resolveLayers(options === null || options === void 0 ? void 0 : options.layers);
|
|
211
353
|
const fullKey = this.buildKey(key, options === null || options === void 0 ? void 0 : options.namespace);
|
|
354
|
+
// Apply compression if enabled and value is large enough
|
|
212
355
|
let processedValue = value;
|
|
213
356
|
if (this.enableCompression &&
|
|
214
357
|
value !== null &&
|
|
@@ -221,7 +364,9 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
221
364
|
});
|
|
222
365
|
processedValue = compressed.data;
|
|
223
366
|
}
|
|
367
|
+
// Wrap value with dependencies
|
|
224
368
|
const wrapped = yield utils_1.DependencyManager.wrapWithDependencies(processedValue, options === null || options === void 0 ? void 0 : options.dependencies);
|
|
369
|
+
// Set in all layers
|
|
225
370
|
const promises = layers.map((layer) => __awaiter(this, void 0, void 0, function* () {
|
|
226
371
|
const provider = this.providers.get(layer);
|
|
227
372
|
if (!provider) {
|
|
@@ -237,21 +382,33 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
237
382
|
yield Promise.all(promises);
|
|
238
383
|
});
|
|
239
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* Resolve cache layers from options
|
|
387
|
+
*/
|
|
240
388
|
resolveLayers(layers) {
|
|
241
389
|
if (layers && layers.length > 0) {
|
|
242
390
|
return layers;
|
|
243
391
|
}
|
|
244
392
|
return this.getDefaultLayers();
|
|
245
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* Get default cache layers
|
|
396
|
+
*/
|
|
246
397
|
getDefaultLayers() {
|
|
247
398
|
return [interfaces_1.CacheLayer.CLS, interfaces_1.CacheLayer.MEMORY, interfaces_1.CacheLayer.REDIS];
|
|
248
399
|
}
|
|
400
|
+
/**
|
|
401
|
+
* Build full cache key with namespace
|
|
402
|
+
*/
|
|
249
403
|
buildKey(key, namespace) {
|
|
250
404
|
if (namespace) {
|
|
251
405
|
return `${namespace}:${key}`;
|
|
252
406
|
}
|
|
253
407
|
return key;
|
|
254
408
|
}
|
|
409
|
+
/**
|
|
410
|
+
* Backfill upper cache layers
|
|
411
|
+
*/
|
|
255
412
|
backfillUpperLayers(key, value, layers, ttl) {
|
|
256
413
|
return __awaiter(this, void 0, void 0, function* () {
|
|
257
414
|
const promises = layers.map((layer) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -269,6 +426,9 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
269
426
|
yield Promise.all(promises);
|
|
270
427
|
});
|
|
271
428
|
}
|
|
429
|
+
/**
|
|
430
|
+
* Record cache hit
|
|
431
|
+
*/
|
|
272
432
|
recordHit(layer) {
|
|
273
433
|
this.stats.hits++;
|
|
274
434
|
if (!this.stats.byLayer[layer]) {
|
|
@@ -277,9 +437,15 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
277
437
|
this.stats.byLayer[layer].hits++;
|
|
278
438
|
this.updateLayerHitRate(layer);
|
|
279
439
|
}
|
|
440
|
+
/**
|
|
441
|
+
* Record cache miss
|
|
442
|
+
*/
|
|
280
443
|
recordMiss() {
|
|
281
444
|
this.stats.misses++;
|
|
282
445
|
}
|
|
446
|
+
/**
|
|
447
|
+
* Update hit rate for a layer
|
|
448
|
+
*/
|
|
283
449
|
updateLayerHitRate(layer) {
|
|
284
450
|
const layerStats = this.stats.byLayer[layer];
|
|
285
451
|
if (layerStats) {
|
|
@@ -287,6 +453,9 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
287
453
|
layerStats.hitRate = total > 0 ? layerStats.hits / total : 0;
|
|
288
454
|
}
|
|
289
455
|
}
|
|
456
|
+
/**
|
|
457
|
+
* Initialize statistics for all layers
|
|
458
|
+
*/
|
|
290
459
|
initializeStats() {
|
|
291
460
|
for (const layer of [interfaces_1.CacheLayer.CLS, interfaces_1.CacheLayer.MEMORY, interfaces_1.CacheLayer.REDIS]) {
|
|
292
461
|
if (!this.stats.byLayer[layer]) {
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import { CacheService } from './cache.service';
|
|
2
|
+
/**
|
|
3
|
+
* Cache warmup configuration
|
|
4
|
+
*/
|
|
2
5
|
export interface CacheWarmupConfig {
|
|
6
|
+
/** Warmup task name */
|
|
3
7
|
name: string;
|
|
8
|
+
/** Function to generate cache data */
|
|
4
9
|
dataProvider: () => Promise<any> | any;
|
|
10
|
+
/** Cache key or key generator */
|
|
5
11
|
key: string | ((data: any) => string);
|
|
12
|
+
/** Cache TTL */
|
|
6
13
|
ttl?: number;
|
|
14
|
+
/** Cache layers to use */
|
|
7
15
|
layers?: string[];
|
|
16
|
+
/** Number of items to process in parallel */
|
|
8
17
|
batchSize?: number;
|
|
18
|
+
/** Whether this warmup is critical (fail if it fails) */
|
|
9
19
|
critical?: boolean;
|
|
10
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Cache warmup result
|
|
23
|
+
*/
|
|
11
24
|
export interface CacheWarmupResult {
|
|
12
25
|
name: string;
|
|
13
26
|
success: boolean;
|
|
@@ -15,20 +28,46 @@ export interface CacheWarmupResult {
|
|
|
15
28
|
duration: number;
|
|
16
29
|
errors: string[];
|
|
17
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Cache warmup service
|
|
33
|
+
*
|
|
34
|
+
* Provides functionality to warm up cache with data before serving requests
|
|
35
|
+
*/
|
|
18
36
|
export declare class CacheWarmupService {
|
|
19
37
|
private readonly cacheService;
|
|
20
38
|
private readonly logger;
|
|
21
39
|
private warmupConfigs;
|
|
22
40
|
constructor(cacheService: CacheService);
|
|
41
|
+
/**
|
|
42
|
+
* Register warmup configurations for a group
|
|
43
|
+
*/
|
|
23
44
|
registerWarmup(groupName: string, configs: CacheWarmupConfig[]): void;
|
|
45
|
+
/**
|
|
46
|
+
* Execute warmup for a specific group
|
|
47
|
+
*/
|
|
24
48
|
warmupGroup(groupName: string): Promise<CacheWarmupResult[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Execute warmup for all registered groups
|
|
51
|
+
*/
|
|
25
52
|
warmupAll(): Promise<Map<string, CacheWarmupResult[]>>;
|
|
53
|
+
/**
|
|
54
|
+
* Get warmup statistics
|
|
55
|
+
*/
|
|
26
56
|
getWarmupStats(): {
|
|
27
57
|
totalGroups: number;
|
|
28
58
|
totalTasks: number;
|
|
29
59
|
taskDetails: any[];
|
|
30
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* Remove warmup configuration
|
|
63
|
+
*/
|
|
31
64
|
removeWarmupGroup(groupName: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Clear all warmup configurations
|
|
67
|
+
*/
|
|
32
68
|
clearWarmupConfigs(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Execute a single warmup task
|
|
71
|
+
*/
|
|
33
72
|
private executeWarmupTask;
|
|
34
73
|
}
|
|
@@ -22,16 +22,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
exports.CacheWarmupService = void 0;
|
|
23
23
|
const common_1 = require("@nestjs/common");
|
|
24
24
|
const cache_service_1 = require("./cache.service");
|
|
25
|
+
/**
|
|
26
|
+
* Cache warmup service
|
|
27
|
+
*
|
|
28
|
+
* Provides functionality to warm up cache with data before serving requests
|
|
29
|
+
*/
|
|
25
30
|
let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
26
31
|
constructor(cacheService) {
|
|
27
32
|
this.cacheService = cacheService;
|
|
28
33
|
this.logger = new common_1.Logger(CacheWarmupService_1.name);
|
|
29
34
|
this.warmupConfigs = new Map();
|
|
30
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Register warmup configurations for a group
|
|
38
|
+
*/
|
|
31
39
|
registerWarmup(groupName, configs) {
|
|
32
40
|
this.warmupConfigs.set(groupName, configs);
|
|
33
41
|
this.logger.debug(`Registered ${configs.length} warmup tasks for group: ${groupName}`);
|
|
34
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Execute warmup for a specific group
|
|
45
|
+
*/
|
|
35
46
|
warmupGroup(groupName) {
|
|
36
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
48
|
const configs = this.warmupConfigs.get(groupName);
|
|
@@ -57,6 +68,9 @@ let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
|
57
68
|
return results;
|
|
58
69
|
});
|
|
59
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Execute warmup for all registered groups
|
|
73
|
+
*/
|
|
60
74
|
warmupAll() {
|
|
61
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
76
|
const results = new Map();
|
|
@@ -81,6 +95,9 @@ let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
|
81
95
|
return results;
|
|
82
96
|
});
|
|
83
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Get warmup statistics
|
|
100
|
+
*/
|
|
84
101
|
getWarmupStats() {
|
|
85
102
|
const totalGroups = this.warmupConfigs.size;
|
|
86
103
|
let totalTasks = 0;
|
|
@@ -98,13 +115,22 @@ let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
|
98
115
|
}
|
|
99
116
|
return { totalGroups, totalTasks, taskDetails };
|
|
100
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Remove warmup configuration
|
|
120
|
+
*/
|
|
101
121
|
removeWarmupGroup(groupName) {
|
|
102
122
|
return this.warmupConfigs.delete(groupName);
|
|
103
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Clear all warmup configurations
|
|
126
|
+
*/
|
|
104
127
|
clearWarmupConfigs() {
|
|
105
128
|
this.warmupConfigs.clear();
|
|
106
129
|
this.logger.debug('All warmup configurations cleared');
|
|
107
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Execute a single warmup task
|
|
133
|
+
*/
|
|
108
134
|
executeWarmupTask(config) {
|
|
109
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
136
|
const startTime = Date.now();
|
|
@@ -113,8 +139,11 @@ let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
|
113
139
|
let success = true;
|
|
114
140
|
try {
|
|
115
141
|
this.logger.debug(`Executing warmup task: ${config.name}`);
|
|
142
|
+
// Get data from provider
|
|
116
143
|
const data = yield Promise.resolve(config.dataProvider());
|
|
144
|
+
// Handle different data types
|
|
117
145
|
if (Array.isArray(data)) {
|
|
146
|
+
// Array of items - warm up each item
|
|
118
147
|
const batchSize = config.batchSize || 100;
|
|
119
148
|
itemCount = data.length;
|
|
120
149
|
for (let i = 0; i < data.length; i += batchSize) {
|
|
@@ -136,6 +165,7 @@ let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
|
136
165
|
}
|
|
137
166
|
}
|
|
138
167
|
else if (data && typeof data === 'object') {
|
|
168
|
+
// Single object - could be a Map or key-value pairs
|
|
139
169
|
if (data instanceof Map) {
|
|
140
170
|
itemCount = data.size;
|
|
141
171
|
for (const [key, value] of data) {
|
|
@@ -151,6 +181,7 @@ let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
|
151
181
|
}
|
|
152
182
|
}
|
|
153
183
|
else {
|
|
184
|
+
// Single object
|
|
154
185
|
itemCount = 1;
|
|
155
186
|
const key = typeof config.key === 'function' ? config.key(data) : config.key;
|
|
156
187
|
yield this.cacheService.set(key, data, {
|
|
@@ -160,6 +191,7 @@ let CacheWarmupService = CacheWarmupService_1 = class CacheWarmupService {
|
|
|
160
191
|
}
|
|
161
192
|
}
|
|
162
193
|
else if (data !== null && data !== undefined) {
|
|
194
|
+
// Primitive value
|
|
163
195
|
itemCount = 1;
|
|
164
196
|
const key = typeof config.key === 'function' ? config.key(data) : config.key;
|
|
165
197
|
yield this.cacheService.set(key, data, {
|
|
@@ -1,2 +1,49 @@
|
|
|
1
1
|
import type { CacheEvictOptions } from '../interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* @CacheEvict decorator - Evict/invalidate cache entries
|
|
4
|
+
*
|
|
5
|
+
* This decorator automatically removes cache entries when a method is executed.
|
|
6
|
+
* Useful for invalidating cache after update/delete operations.
|
|
7
|
+
*
|
|
8
|
+
* @param options - Cache evict options
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* class UserService {
|
|
13
|
+
* // Evict single cache entry
|
|
14
|
+
* @CacheEvict({
|
|
15
|
+
* keys: [(id) => `user:${id}`]
|
|
16
|
+
* })
|
|
17
|
+
* async deleteUser(id: string) {
|
|
18
|
+
* await this.repo.delete(id);
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* // Evict multiple entries with patterns
|
|
22
|
+
* @CacheEvict({
|
|
23
|
+
* patterns: ['user:*', 'users:list:*']
|
|
24
|
+
* })
|
|
25
|
+
* async updateAllUsers() {
|
|
26
|
+
* await this.repo.update({}, { status: 'active' });
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* // Invalidate by tags
|
|
30
|
+
* @CacheEvict({
|
|
31
|
+
* tags: ['user-list', 'user-data']
|
|
32
|
+
* })
|
|
33
|
+
* async createUser(data: CreateUserDto) {
|
|
34
|
+
* return await this.repo.save(data);
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* // Conditional eviction
|
|
38
|
+
* @CacheEvict({
|
|
39
|
+
* keys: [(id) => `user:${id}`],
|
|
40
|
+
* condition: (id, result) => result.success
|
|
41
|
+
* })
|
|
42
|
+
* async updateUser(id: string, data: any) {
|
|
43
|
+
* const result = await this.repo.update(id, data);
|
|
44
|
+
* return { success: result.affected > 0 };
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
2
49
|
export declare function CacheEvict(options?: CacheEvictOptions): MethodDecorator;
|
|
@@ -12,6 +12,53 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.CacheEvict = CacheEvict;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const cacheable_decorator_1 = require("./cacheable.decorator");
|
|
15
|
+
/**
|
|
16
|
+
* @CacheEvict decorator - Evict/invalidate cache entries
|
|
17
|
+
*
|
|
18
|
+
* This decorator automatically removes cache entries when a method is executed.
|
|
19
|
+
* Useful for invalidating cache after update/delete operations.
|
|
20
|
+
*
|
|
21
|
+
* @param options - Cache evict options
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* class UserService {
|
|
26
|
+
* // Evict single cache entry
|
|
27
|
+
* @CacheEvict({
|
|
28
|
+
* keys: [(id) => `user:${id}`]
|
|
29
|
+
* })
|
|
30
|
+
* async deleteUser(id: string) {
|
|
31
|
+
* await this.repo.delete(id);
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* // Evict multiple entries with patterns
|
|
35
|
+
* @CacheEvict({
|
|
36
|
+
* patterns: ['user:*', 'users:list:*']
|
|
37
|
+
* })
|
|
38
|
+
* async updateAllUsers() {
|
|
39
|
+
* await this.repo.update({}, { status: 'active' });
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* // Invalidate by tags
|
|
43
|
+
* @CacheEvict({
|
|
44
|
+
* tags: ['user-list', 'user-data']
|
|
45
|
+
* })
|
|
46
|
+
* async createUser(data: CreateUserDto) {
|
|
47
|
+
* return await this.repo.save(data);
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* // Conditional eviction
|
|
51
|
+
* @CacheEvict({
|
|
52
|
+
* keys: [(id) => `user:${id}`],
|
|
53
|
+
* condition: (id, result) => result.success
|
|
54
|
+
* })
|
|
55
|
+
* async updateUser(id: string, data: any) {
|
|
56
|
+
* const result = await this.repo.update(id, data);
|
|
57
|
+
* return { success: result.affected > 0 };
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
15
62
|
function CacheEvict(options = {}) {
|
|
16
63
|
const logger = new common_1.Logger('CacheEvictDecorator');
|
|
17
64
|
return function (target, propertyKey, descriptor) {
|
|
@@ -26,21 +73,25 @@ function CacheEvict(options = {}) {
|
|
|
26
73
|
}
|
|
27
74
|
const evictCache = (result) => __awaiter(this, void 0, void 0, function* () {
|
|
28
75
|
try {
|
|
76
|
+
// Check condition
|
|
29
77
|
if (options.condition) {
|
|
30
78
|
const shouldEvict = yield Promise.resolve(options.condition(...args, result));
|
|
31
79
|
if (!shouldEvict) {
|
|
32
80
|
return;
|
|
33
81
|
}
|
|
34
82
|
}
|
|
83
|
+
// Evict by keys
|
|
35
84
|
if (options.keys && options.keys.length > 0) {
|
|
36
85
|
const resolvedKeys = options.keys.map((keyOrFn) => typeof keyOrFn === 'function' ? keyOrFn(...args) : keyOrFn);
|
|
37
86
|
yield cacheService.delete(resolvedKeys, options.layers);
|
|
38
87
|
}
|
|
88
|
+
// Evict by patterns
|
|
39
89
|
if (options.patterns && options.patterns.length > 0) {
|
|
40
90
|
for (const pattern of options.patterns) {
|
|
41
91
|
yield cacheService.deletePattern(pattern, options.layers);
|
|
42
92
|
}
|
|
43
93
|
}
|
|
94
|
+
// Invalidate tags
|
|
44
95
|
if (options.tags && options.tags.length > 0) {
|
|
45
96
|
yield cacheService.invalidateTags(options.tags);
|
|
46
97
|
}
|
|
@@ -50,19 +101,24 @@ function CacheEvict(options = {}) {
|
|
|
50
101
|
}
|
|
51
102
|
});
|
|
52
103
|
try {
|
|
104
|
+
// Evict before method execution
|
|
53
105
|
if (options.timing === 'before') {
|
|
54
106
|
yield evictCache();
|
|
55
107
|
}
|
|
108
|
+
// Execute original method
|
|
56
109
|
const result = yield originalMethod.apply(this, args);
|
|
110
|
+
// Evict after method execution (default)
|
|
57
111
|
if (options.timing !== 'before') {
|
|
58
112
|
yield evictCache(result);
|
|
59
113
|
}
|
|
60
114
|
return result;
|
|
61
115
|
}
|
|
62
116
|
catch (error) {
|
|
117
|
+
// Still try to evict on error if timing is 'before'
|
|
63
118
|
if (options.timing === 'before') {
|
|
64
119
|
throw error;
|
|
65
120
|
}
|
|
121
|
+
// For 'after' timing, don't evict on error
|
|
66
122
|
throw error;
|
|
67
123
|
}
|
|
68
124
|
});
|