From b085e8bd11675ddabb2e8a652579f30af354492e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sedat=20=C3=96ZT=C3=9CRK?= <76204082+iamsedatozturk@users.noreply.github.com> Date: Fri, 16 Jan 2026 17:52:52 +0300 Subject: [PATCH] =?UTF-8?q?LanguageText=20de=C4=9Fi=C5=9Fiklikleri=20Redis?= =?UTF-8?q?=20Clear=20Cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LanguageTextAppService.cs | 14 ++++++- .../Seeds/LanguagesData.json | 6 +++ .../Seeds/ListFormSeeder_Saas.cs | 27 ++++++++----- ui/src/services/UiEvalService.tsx | 39 +++++++++++++++++++ ui/src/services/languageText.service.ts | 15 +++++++ 5 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 ui/src/services/languageText.service.ts diff --git a/api/modules/Erp.Languages/Erp.Languages.Application/LanguageTextAppService.cs b/api/modules/Erp.Languages/Erp.Languages.Application/LanguageTextAppService.cs index 05d0238e..270ad05c 100644 --- a/api/modules/Erp.Languages/Erp.Languages.Application/LanguageTextAppService.cs +++ b/api/modules/Erp.Languages/Erp.Languages.Application/LanguageTextAppService.cs @@ -1,6 +1,8 @@ using Erp.Languages.Entities; using Erp.Languages.Localization; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using StackExchange.Redis; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -27,10 +29,12 @@ public class LanguageTextAppService : CrudAppService< { private readonly IRepository _repositoryText; private readonly IRepository _repositoryKey; + private readonly IConfiguration _configuration; public LanguageTextAppService( IRepository repositoryText, - IRepository repositoryKey + IRepository repositoryKey, + IConfiguration configuration ) : base(repositoryText) { @@ -38,6 +42,7 @@ public class LanguageTextAppService : CrudAppService< ObjectMapperContext = typeof(LanguagesApplicationModule); _repositoryText = repositoryText; _repositoryKey = repositoryKey; + _configuration = configuration; } public override async Task CreateAsync(LanguageTextCreateUpdateDto input) @@ -124,6 +129,13 @@ public class LanguageTextAppService : CrudAppService< return ObjectMapper.Map, List>(item); } + + public async Task ClearRedisCacheAsync() + { + var redis = ConnectionMultiplexer.Connect(_configuration["Redis:Configuration"]!); + var db = redis.GetDatabase(); + await db.ExecuteAsync("FLUSHALL"); + } protected virtual IQueryable ApplySorting(IQueryable query, LanguageTextTranslatedRequestDto input) { diff --git a/api/src/Erp.Platform.DbMigrator/Seeds/LanguagesData.json b/api/src/Erp.Platform.DbMigrator/Seeds/LanguagesData.json index 60df42e8..7254a59a 100644 --- a/api/src/Erp.Platform.DbMigrator/Seeds/LanguagesData.json +++ b/api/src/Erp.Platform.DbMigrator/Seeds/LanguagesData.json @@ -3007,6 +3007,12 @@ "en": "Background Workers are being renewed.", "tr": "Arka Plan Çalışanları yenileniyor." }, + { + "resourceName": "Platform", + "key": "App.ClearRedisCache.Message", + "en": "Redis cache is being cleared.", + "tr": "Redis önbelleği temizleniyor." + }, { "resourceName": "Platform", "key": "LoginEndDate", diff --git a/api/src/Erp.Platform.DbMigrator/Seeds/ListFormSeeder_Saas.cs b/api/src/Erp.Platform.DbMigrator/Seeds/ListFormSeeder_Saas.cs index cc7d07cb..132c8955 100644 --- a/api/src/Erp.Platform.DbMigrator/Seeds/ListFormSeeder_Saas.cs +++ b/api/src/Erp.Platform.DbMigrator/Seeds/ListFormSeeder_Saas.cs @@ -1841,16 +1841,25 @@ public class ListFormSeeder_Saas : IDataSeedContributor, ITransientDependency PagerOptionJson = DefaultPagerOptionJson, EditingOptionJson = DefaultEditingOptionJson(listFormName, 600, 400, true, true, true, true, false), EditingFormJson = JsonSerializer.Serialize(new List() { - new() { Order=1, ColCount=1, ColSpan=1, ItemType="group", Items= - [ - new EditingFormItemDto { Order = 1, DataField = "CultureName", ColSpan = 1, IsRequired = true, EditorType2=EditorTypes.dxSelectBox, EditorOptions=EditorOptionValues.ShowClearButton }, - new EditingFormItemDto { Order = 2, DataField = "ResourceName", ColSpan = 1, IsRequired = true, EditorType2=EditorTypes.dxSelectBox, EditorOptions=EditorOptionValues.ShowClearButton }, - new EditingFormItemDto { Order = 3, DataField = "Key", ColSpan = 1, IsRequired = true, EditorType2=EditorTypes.dxAutocomplete, EditorOptions=EditorOptionValues.ShowClearButton }, - new EditingFormItemDto { Order = 4, DataField = "Value", ColSpan = 1, IsRequired = true, EditorType2=EditorTypes.dxTextBox }, - ] - } - }), + new() { Order=1, ColCount=1, ColSpan=1, ItemType="group", Items= + [ + new EditingFormItemDto { Order = 1, DataField = "CultureName", ColSpan = 1, IsRequired = true, EditorType2=EditorTypes.dxSelectBox, EditorOptions=EditorOptionValues.ShowClearButton }, + new EditingFormItemDto { Order = 2, DataField = "ResourceName", ColSpan = 1, IsRequired = true, EditorType2=EditorTypes.dxSelectBox, EditorOptions=EditorOptionValues.ShowClearButton }, + new EditingFormItemDto { Order = 3, DataField = "Key", ColSpan = 1, IsRequired = true, EditorType2=EditorTypes.dxAutocomplete, EditorOptions=EditorOptionValues.ShowClearButton }, + new EditingFormItemDto { Order = 4, DataField = "Value", ColSpan = 1, IsRequired = true, EditorType2=EditorTypes.dxTextBox }, + ] + }}), InsertFieldsDefaultValueJson = DefaultInsertFieldsDefaultValueJson(), + CommandColumnJson = JsonSerializer.Serialize(new CommandColumnDto[] { + new() { + ButtonPosition= UiCommandButtonPositionTypeEnum.Toolbar, + Hint = "Clear Redis Cache", + Text = "Clear Redis Cache", + AuthName = listFormName, + OnClick = "UiEvalService.ApiClearRedisCache();", + IsVisible = true, + }, + }), }, autoSave: true ); diff --git a/ui/src/services/UiEvalService.tsx b/ui/src/services/UiEvalService.tsx index ce086ee3..d7902742 100644 --- a/ui/src/services/UiEvalService.tsx +++ b/ui/src/services/UiEvalService.tsx @@ -2,6 +2,7 @@ import { Notification, toast } from '@/components/ui' import { generateBackgroundWorkers } from '@/services/background-worker.service' import { getLocalization } from '@/services/localization.service' import { store } from '@/store' +import { clearRedisCache } from './languageText.service' export abstract class UiEvalService { static Init = () => { @@ -45,6 +46,44 @@ export abstract class UiEvalService { }, ) } + + static ApiClearRedisCache = () => { + // Get store state directly instead of using hook + const state = store.getState() + const { texts, config } = state.abpConfig + + // Create translate function similar to useLocalization hook + const translate = ( + localizationKey: string, + params?: Record, + defaultResourceName?: string, + ): string => { + if (!texts) { + return localizationKey + } + return getLocalization( + texts, + defaultResourceName ?? config?.localization?.defaultResourceName, + localizationKey, + params, + ) + } + + const asyncCall = async () => { + await clearRedisCache() + } + + asyncCall() + + toast.push( + + {translate('::App.ClearRedisCache.Message')} + , + { + placement: 'top-end', + }, + ) + } } const _global = (window || global) as any diff --git a/ui/src/services/languageText.service.ts b/ui/src/services/languageText.service.ts new file mode 100644 index 00000000..cd22bd1f --- /dev/null +++ b/ui/src/services/languageText.service.ts @@ -0,0 +1,15 @@ +import { AxiosError } from 'axios' +import apiService from './api.service' + +export const clearRedisCache = async () => { + try { + return await apiService.fetchData>({ + method: 'POST', + url: '/api/app/language-text/clear-redis-cache', + }) + } catch (error) { + if (error instanceof AxiosError) { + return error.response?.data + } + } +}