LanguageText değişiklikleri Redis Clear Cache

This commit is contained in:
Sedat ÖZTÜRK 2026-01-16 17:52:52 +03:00
parent d0bfbbd811
commit b085e8bd11
5 changed files with 91 additions and 10 deletions

View file

@ -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<LanguageText, Guid> _repositoryText;
private readonly IRepository<LanguageKey, Guid> _repositoryKey;
private readonly IConfiguration _configuration;
public LanguageTextAppService(
IRepository<LanguageText, Guid> repositoryText,
IRepository<LanguageKey, Guid> repositoryKey
IRepository<LanguageKey, Guid> 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<LanguageTextDto> CreateAsync(LanguageTextCreateUpdateDto input)
@ -125,6 +130,13 @@ public class LanguageTextAppService : CrudAppService<
return ObjectMapper.Map<List<LanguageText>, List<LanguageTextDto>>(item);
}
public async Task ClearRedisCacheAsync()
{
var redis = ConnectionMultiplexer.Connect(_configuration["Redis:Configuration"]!);
var db = redis.GetDatabase();
await db.ExecuteAsync("FLUSHALL");
}
protected virtual IQueryable<LanguageKey> ApplySorting(IQueryable<LanguageKey> query, LanguageTextTranslatedRequestDto input)
{
//Try to sort query if available

View file

@ -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",

View file

@ -1848,9 +1848,18 @@ public class ListFormSeeder_Saas : IDataSeedContributor, ITransientDependency
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
);

View file

@ -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<string, string | number>,
defaultResourceName?: string,
): string => {
if (!texts) {
return localizationKey
}
return getLocalization(
texts,
defaultResourceName ?? config?.localization?.defaultResourceName,
localizationKey,
params,
)
}
const asyncCall = async () => {
await clearRedisCache()
}
asyncCall()
toast.push(
<Notification type="success" duration={2000}>
{translate('::App.ClearRedisCache.Message')}
</Notification>,
{
placement: 'top-end',
},
)
}
}
const _global = (window || global) as any

View file

@ -0,0 +1,15 @@
import { AxiosError } from 'axios'
import apiService from './api.service'
export const clearRedisCache = async () => {
try {
return await apiService.fetchData<void, Record<string, string>>({
method: 'POST',
url: '/api/app/language-text/clear-redis-cache',
})
} catch (error) {
if (error instanceof AxiosError) {
return error.response?.data
}
}
}