-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Feature: Client Cache for Document Item Models #19923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 42 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
a12db87
extend controller base
madsrasmussen 5d6415f
extend controller base
madsrasmussen 05a4235
add package for management api
madsrasmussen 6212027
add signalr as external package
madsrasmussen 2b1be18
connect to server event hub
madsrasmussen 2490bf8
do no act on undefined
madsrasmussen 8c592e3
add event subject
madsrasmussen c139362
correct alias
madsrasmussen 62799bd
export token
madsrasmussen 5a3f8f9
add helper methods
madsrasmussen 2deb7cc
cache server responses
madsrasmussen ad257cf
fix import
madsrasmussen 03c1fc8
use helpers
madsrasmussen 1f1baa6
add detail request manager
madsrasmussen a2c3283
implement for document type
madsrasmussen 9aa73a7
implement for data type
madsrasmussen 9d33c00
add method for update
madsrasmussen ba732e3
add support for create method
madsrasmussen 9e1deb6
align code
madsrasmussen cefc5e0
Update detail-request.manager.ts
madsrasmussen b38cdf2
move explicit naming
madsrasmussen 9905302
move into folder
madsrasmussen eef5acb
collect server code in folder
madsrasmussen 0045a74
add implementation for data type request manager
madsrasmussen 9058d26
implement for document type
madsrasmussen c9f701f
only cache when we have connection to the server events
madsrasmussen da203e6
update
madsrasmussen de86ac7
fix imports
madsrasmussen 107e6d6
introduce item cache
madsrasmussen f4af0e3
call trough get items controller
madsrasmussen feba22b
remove log
madsrasmussen 523e63b
add unit tests for item cache
madsrasmussen ebdb339
Create cache.test.ts
madsrasmussen 1f181c3
use sync method to lookup data type item
madsrasmussen 82be7df
Merge branch 'main' into v16/feature/entity-detail-runtime-cache
madsrasmussen 2cdfef1
use correct alias
madsrasmussen c663462
Merge branch 'v16/feature/entity-detail-runtime-cache' into v16/featu…
madsrasmussen bfa9918
remove unused code
madsrasmussen 2df8103
Merge branch 'main' into v16/feature/item-data-runtime-cache
iOvergaard aa5c1d6
split detail cache invalidation from request manager
madsrasmussen 729d65b
introduce item cache invalidation manager
madsrasmussen 7847a7f
Merge branch 'main' into v16/feature/item-data-runtime-cache
madsrasmussen 5961dd6
remove unused
madsrasmussen c29c498
invalidate documents when document types changes
madsrasmussen e8d3f65
align naming
madsrasmussen cffd86e
add method to get unique
madsrasmussen 1a6f81d
use server model instead of mapping
madsrasmussen e74a23a
call method
madsrasmussen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/Umbraco.Web.UI.Client/src/packages/data-type/entry-point.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { UmbManagementApiDataTypeDetailDataCacheInvalidationManager } from './repository/detail/server-data-source/data-type-detail.server.cache-invalidation.manager.js'; | ||
| import type { UmbEntryPointOnInit, UmbEntryPointOnUnload } from '@umbraco-cms/backoffice/extension-api'; | ||
|
|
||
| let detailDataCacheInvalidationManager: UmbManagementApiDataTypeDetailDataCacheInvalidationManager | undefined; | ||
|
|
||
| export const onInit: UmbEntryPointOnInit = (host) => { | ||
| detailDataCacheInvalidationManager = new UmbManagementApiDataTypeDetailDataCacheInvalidationManager(host); | ||
| }; | ||
|
|
||
| export const onUnload: UmbEntryPointOnUnload = () => { | ||
| detailDataCacheInvalidationManager?.destroy(); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...epository/detail/server-data-source/data-type-detail.server.cache-invalidation.manager.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { dataTypeDetailCache } from './data-type-detail.server.cache.js'; | ||
| import { UmbManagementApiDetailDataCacheInvalidationManager } from '@umbraco-cms/backoffice/management-api'; | ||
| import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; | ||
| import type { DataTypeResponseModel } from '@umbraco-cms/backoffice/external/backend-api'; | ||
|
|
||
| export class UmbManagementApiDataTypeDetailDataCacheInvalidationManager extends UmbManagementApiDetailDataCacheInvalidationManager<DataTypeResponseModel> { | ||
| constructor(host: UmbControllerHost) { | ||
| super(host, { | ||
| dataCache: dataTypeDetailCache, | ||
| serverEventSources: ['Umbraco:CMS:DataType'], | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entry-point.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { UmbManagementApiDocumentTypeDetailDataCacheInvalidationManager } from './repository/detail/server-data-source/document-type-detail.server.cache-invalidation.manager.js'; | ||
| import type { UmbEntryPointOnInit, UmbEntryPointOnUnload } from '@umbraco-cms/backoffice/extension-api'; | ||
|
|
||
| let detailDataCacheInvalidationManager: UmbManagementApiDocumentTypeDetailDataCacheInvalidationManager | undefined; | ||
|
|
||
| export const onInit: UmbEntryPointOnInit = (host) => { | ||
| detailDataCacheInvalidationManager = new UmbManagementApiDocumentTypeDetailDataCacheInvalidationManager(host); | ||
| }; | ||
|
|
||
| export const onUnload: UmbEntryPointOnUnload = () => { | ||
| detailDataCacheInvalidationManager?.destroy(); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...itory/detail/server-data-source/document-type-detail.server.cache-invalidation.manager.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { documentTypeDetailCache } from './document-type-detail.server.cache.js'; | ||
| import { UmbManagementApiDetailDataCacheInvalidationManager } from '@umbraco-cms/backoffice/management-api'; | ||
| import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; | ||
| import type { DocumentTypeResponseModel } from '@umbraco-cms/backoffice/external/backend-api'; | ||
|
|
||
| export class UmbManagementApiDocumentTypeDetailDataCacheInvalidationManager extends UmbManagementApiDetailDataCacheInvalidationManager<DocumentTypeResponseModel> { | ||
| constructor(host: UmbControllerHost) { | ||
| super(host, { | ||
| dataCache: documentTypeDetailCache, | ||
| serverEventSources: ['Umbraco:CMS:DocumentType'], | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/Umbraco.Web.UI.Client/src/packages/documents/documents/entry-point.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { UmbManagementApiDocumentItemDataCacheInvalidationManager } from './item/repository/document-item.server.cache-invalidation.manager.js'; | ||
| import type { UmbEntryPointOnInit, UmbEntryPointOnUnload } from '@umbraco-cms/backoffice/extension-api'; | ||
|
|
||
| let itemDataCacheInvalidationManager: UmbManagementApiDocumentItemDataCacheInvalidationManager | undefined; | ||
|
|
||
| export const onInit: UmbEntryPointOnInit = (host) => { | ||
| itemDataCacheInvalidationManager = new UmbManagementApiDocumentItemDataCacheInvalidationManager(host); | ||
| }; | ||
|
|
||
| export const onUnload: UmbEntryPointOnUnload = () => { | ||
| itemDataCacheInvalidationManager?.destroy(); | ||
| }; |
13 changes: 13 additions & 0 deletions
13
...es/documents/documents/item/repository/document-item.server.cache-invalidation.manager.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { documentItemCache } from './document-item.server.cache.js'; | ||
| import { UmbManagementApiItemDataCacheInvalidationManager } from '@umbraco-cms/backoffice/management-api'; | ||
| import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; | ||
| import type { DocumentItemResponseModel } from '@umbraco-cms/backoffice/external/backend-api'; | ||
|
|
||
| export class UmbManagementApiDocumentItemDataCacheInvalidationManager extends UmbManagementApiItemDataCacheInvalidationManager<DocumentItemResponseModel> { | ||
| constructor(host: UmbControllerHost) { | ||
| super(host, { | ||
| dataCache: documentItemCache, | ||
| serverEventSources: ['Umbraco:CMS:Document'], | ||
| }); | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
....UI.Client/src/packages/documents/documents/item/repository/document-item.server.cache.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import type { DocumentItemResponseModel } from '@umbraco-cms/backoffice/external/backend-api'; | ||
| import { UmbManagementApiItemDataCache } from '@umbraco-cms/backoffice/management-api'; | ||
|
|
||
| const documentItemCache = new UmbManagementApiItemDataCache<DocumentItemResponseModel>(); | ||
|
|
||
| export { documentItemCache }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
.../src/packages/documents/documents/item/repository/document-item.server.request-manager.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* eslint-disable local-rules/no-direct-api-import */ | ||
| import { documentItemCache } from './document-item.server.cache.js'; | ||
| import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; | ||
| import { DocumentService, type DocumentItemResponseModel } from '@umbraco-cms/backoffice/external/backend-api'; | ||
| import { UmbManagementApiItemDataRequestManager } from '@umbraco-cms/backoffice/management-api'; | ||
|
|
||
| export class UmbManagementApiDocumentItemDataRequestManager extends UmbManagementApiItemDataRequestManager<DocumentItemResponseModel> { | ||
| constructor(host: UmbControllerHost) { | ||
| super(host, { | ||
| getItems: (ids: Array<string>) => DocumentService.getItemDocument({ query: { id: ids } }), | ||
| dataCache: documentItemCache, | ||
| serverEventSource: 'Umbraco:CMS:Document', | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/Umbraco.Web.UI.Client/src/packages/management-api/detail/cache-invalidation.manager.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { UMB_MANAGEMENT_API_SERVER_EVENT_CONTEXT } from '../server-event/constants.js'; | ||
| import type { UmbManagementApiDetailDataCache } from './cache.js'; | ||
| import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; | ||
| import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; | ||
|
|
||
| export interface UmbManagementApiDetailDataInvalidationManagerArgs<DetailResponseModelType> { | ||
| dataCache: UmbManagementApiDetailDataCache<DetailResponseModelType>; | ||
| serverEventSources: Array<string>; | ||
| } | ||
|
|
||
| export class UmbManagementApiDetailDataCacheInvalidationManager<DetailResponseModelType> extends UmbControllerBase { | ||
| #dataCache: UmbManagementApiDetailDataCache<DetailResponseModelType>; | ||
| #serverEventSources: Array<string>; | ||
| #serverEventContext?: typeof UMB_MANAGEMENT_API_SERVER_EVENT_CONTEXT.TYPE; | ||
|
|
||
| constructor( | ||
| host: UmbControllerHost, | ||
| args: UmbManagementApiDetailDataInvalidationManagerArgs<DetailResponseModelType>, | ||
| ) { | ||
| super(host); | ||
| { | ||
| this.#dataCache = args.dataCache; | ||
| this.#serverEventSources = args.serverEventSources; | ||
|
|
||
| this.consumeContext(UMB_MANAGEMENT_API_SERVER_EVENT_CONTEXT, (context) => { | ||
| this.#serverEventContext = context; | ||
| this.#observeServerEvents(); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| #observeServerEvents() { | ||
| this.observe( | ||
| this.#serverEventContext?.byEventSourcesAndTypes(this.#serverEventSources, ['Updated', 'Deleted']), | ||
| (event) => { | ||
| if (!event) return; | ||
| this.#dataCache.delete(event.key); | ||
| }, | ||
| 'umbObserveServerEvents', | ||
| ); | ||
| } | ||
|
|
||
| override destroy(): void { | ||
| this.#dataCache.clear(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/Umbraco.Web.UI.Client/src/packages/management-api/detail/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export * from './detail-data.request-manager.js'; | ||
| export * from './cache.js'; | ||
| export * from './cache-invalidation.manager.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export * from './detail/index.js'; | ||
| export * from './item/index.js'; | ||
| export * from './server-event/constants.js'; |
44 changes: 44 additions & 0 deletions
44
src/Umbraco.Web.UI.Client/src/packages/management-api/item/cache-invalidation.manager.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { UMB_MANAGEMENT_API_SERVER_EVENT_CONTEXT } from '../server-event/constants.js'; | ||
| import type { UmbManagementApiItemDataCache } from './cache.js'; | ||
| import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; | ||
| import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; | ||
|
|
||
| export interface UmbManagementApiItemDataInvalidationManagerArgs<ItemResponseModelType> { | ||
| dataCache: UmbManagementApiItemDataCache<ItemResponseModelType>; | ||
| serverEventSources: Array<string>; | ||
| } | ||
|
|
||
| export class UmbManagementApiItemDataCacheInvalidationManager<ItemResponseModelType> extends UmbControllerBase { | ||
| #dataCache: UmbManagementApiItemDataCache<ItemResponseModelType>; | ||
| #serverEventSources: Array<string>; | ||
| #serverEventContext?: typeof UMB_MANAGEMENT_API_SERVER_EVENT_CONTEXT.TYPE; | ||
|
|
||
| constructor(host: UmbControllerHost, args: UmbManagementApiItemDataInvalidationManagerArgs<ItemResponseModelType>) { | ||
| super(host); | ||
| { | ||
| this.#dataCache = args.dataCache; | ||
| this.#serverEventSources = args.serverEventSources; | ||
|
|
||
| this.consumeContext(UMB_MANAGEMENT_API_SERVER_EVENT_CONTEXT, (context) => { | ||
| this.#serverEventContext = context; | ||
| this.#observeServerEvents(); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| #observeServerEvents() { | ||
| // Invalidate cache entries when entities are updated or deleted | ||
| this.observe( | ||
| this.#serverEventContext?.byEventSourcesAndTypes(this.#serverEventSources, ['Updated', 'Deleted']), | ||
| (event) => { | ||
| if (!event) return; | ||
| this.#dataCache.delete(event.key); | ||
| }, | ||
| 'umbObserveServerEvents', | ||
| ); | ||
| } | ||
|
|
||
| override destroy(): void { | ||
| this.#dataCache.clear(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.