Release v1.0.0 #16
.envDbInitializer.csDependencyInjection.csnuget.config
.gitea/workflows
.gitignoreApiDto
ApiDto.csproj
Backend.slnDockerfileCommon
Requests
Responses
Endpoint
Backend.httpISaveSettings.cs
README.mdCommon
Attributes
BadRequestResponseAttribute.csCacheMaxAgeAttribute.csLocalhostAttribute.csMaintenanceModeIgnoreAttribute.csNotFoundResponseAttribute.csSwaggerDefaultAttribute.csTokenAuthenticationAttribute.cs
Exceptions
Interfaces
Services
Configuration
Core
BackgroundTasks
Middleware
CacheMaxAgeMiddleware.csCookieAuthorizationMiddleware.csCustomExceptionHandlerMiddleware.csJwtRevocationMiddleware.csMaintenanceModeMiddleware.cs
Startup
Model
SwaggerOptions
Validation
Controllers
BaseController.cs
Endpoint.csprojProgram.csConfiguration
V1
AuthController.csCampusController.csDisciplineController.csFacultyController.csGroupController.csImportController.csLectureHallController.csProfessorController.csScheduleController.cs
WeatherForecastController.csSync
WeatherForecast.cswwwroot
css
swagger
Security
SqlData
Application
Application.csprojDependencyInjection.cs
Common
Cqrs
Campus
Queries
Discipline
Queries
Faculty
Queries
Group
Queries
LectureHall
Queries
Professor
Queries
GetProfessorDetails
GetProfessorDetailsBySearch
GetProfessorList
Schedule
Interfaces
Domain
Domain.csproj
Schedule
Migrations
MysqlMigrations
Migrations
20240601023106_InitialMigration.Designer.cs20240601023106_InitialMigration.cs20241027034820_RemoveUnusedRef.Designer.cs20241027034820_RemoveUnusedRef.csUberDbContextModelSnapshot.cs
MysqlMigrations.csprojPsqlMigrations
Migrations
20240601021702_InitialMigration.Designer.cs20240601021702_InitialMigration.cs20241027032753_RemoveUnusedRef.Designer.cs20241027032753_RemoveUnusedRef.csUberDbContextModelSnapshot.cs
PsqlMigrations.csprojSqliteMigrations
Persistence
Common
BaseDbContext.csConfigurationResolver.csDatabaseProvider.csDbContextFactory.csModelBuilderExtensions.cs
Contexts
Schedule
EntityTypeConfigurations
Persistence.csprojUberDbContext.cs@ -17,12 +17,43 @@ public class DistributedCacheService(IDistributedCache cache) : ICacheService
|
||||
SlidingExpiration = slidingExpiration
|
||||
};
|
||||
|
||||
var type = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T);
|
||||
if (type.IsPrimitive || type == typeof(string) || type == typeof(DateTime))
|
||||
{
|
||||
await cache.SetStringAsync(key, value?.ToString() ?? string.Empty, options, cancellationToken);
|
||||
return;
|
||||
}
|
||||
|
||||
var serializedValue = value as byte[] ?? JsonSerializer.SerializeToUtf8Bytes(value);
|
||||
await cache.SetAsync(key, serializedValue, options, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<T?> GetAsync<T>(string key, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var type = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T);
|
||||
|
||||
if (type.IsPrimitive || type == typeof(string) || type == typeof(DateTime))
|
||||
{
|
||||
var primitiveValue = await cache.GetStringAsync(key, cancellationToken);
|
||||
|
||||
if (string.IsNullOrEmpty(primitiveValue))
|
||||
return default;
|
||||
|
||||
if (type == typeof(string))
|
||||
return (T?)(object?)primitiveValue;
|
||||
|
||||
var tryParseMethod = type.GetMethod("TryParse", [typeof(string), type.MakeByRefType()])
|
||||
?? throw new NotSupportedException($"Type {type.Name} does not support TryParse.");
|
||||
|
||||
var parameters = new[] { primitiveValue, Activator.CreateInstance(type) };
|
||||
var success = (bool)tryParseMethod.Invoke(null, parameters)!;
|
||||
|
||||
if (success)
|
||||
return (T)parameters[1]!;
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
var cachedValue = await cache.GetAsync(key, cancellationToken);
|
||||
return cachedValue == null ? default : JsonSerializer.Deserialize<T>(cachedValue);
|
||||
}
|
||||
|
@ -17,17 +17,41 @@ public class MemoryCacheService(IMemoryCache cache) : ICacheService
|
||||
SlidingExpiration = slidingExpiration
|
||||
};
|
||||
|
||||
var type = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T);
|
||||
if (type.IsPrimitive || type == typeof(string) || type == typeof(DateTime))
|
||||
{
|
||||
cache.Set(key, value?.ToString() ?? string.Empty, options);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
cache.Set(key, value as byte[] ?? JsonSerializer.SerializeToUtf8Bytes(value), options);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<T?> GetAsync<T>(string key, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var type = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T);
|
||||
|
||||
if (!type.IsPrimitive && type != typeof(string) && type != typeof(DateTime))
|
||||
return Task.FromResult(
|
||||
cache.TryGetValue(key, out byte[]? value) ?
|
||||
JsonSerializer.Deserialize<T>(value) :
|
||||
default
|
||||
cache.TryGetValue(key, out byte[]? value) ? JsonSerializer.Deserialize<T>(value) : default
|
||||
);
|
||||
|
||||
var primitiveValue = cache.Get(key);
|
||||
|
||||
if (string.IsNullOrEmpty(primitiveValue?.ToString()))
|
||||
return Task.FromResult<T?>(default);
|
||||
|
||||
if (type == typeof(string))
|
||||
return Task.FromResult((T?)primitiveValue);
|
||||
|
||||
var tryParseMethod = type.GetMethod("TryParse", [typeof(string), type.MakeByRefType()])
|
||||
?? throw new NotSupportedException($"Type {type.Name} does not support TryParse.");
|
||||
|
||||
var parameters = new[] { primitiveValue, Activator.CreateInstance(type) };
|
||||
var success = (bool)tryParseMethod.Invoke(null, parameters)!;
|
||||
|
||||
return success ? Task.FromResult((T?)parameters[1]) : Task.FromResult<T?>(default);
|
||||
}
|
||||
|
||||
public Task RemoveAsync(string key, CancellationToken cancellationToken = default)
|
||||
|
Reference in New Issue
Block a user