Add a cache system on the referential info

+ Add an identity service
This commit is contained in:
Sébastien André
2021-04-17 22:17:45 +02:00
parent 0bb9ed2a30
commit 143127cd01
30 changed files with 955 additions and 570 deletions

View File

@@ -1,23 +1,31 @@
using System;
using System.Collections.Generic;
using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainBusiness.Interfaces;
using skydiveLogs_api.DomainService.Repositories;
using skydiveLogs_api.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
namespace skydiveLogs_api.DomainBusiness
{
public class AircraftService : IAircraftService
{
public AircraftService(IAircraftRepository aircraftRepository)
#region Public Constructors
public AircraftService(IAircraftRepository aircraftRepository,
ICacheService cacheService)
{
_aircraftRepository = aircraftRepository;
_cacheService = cacheService;
}
#endregion Public Constructors
#region Public Methods
public void AddNewAircraft(Aircraft newAircraft)
{
_aircraftRepository.Add(newAircraft);
_cacheService.Delete(CacheType.Aircraft);
}
public void DeleteAircraftById(int id)
@@ -27,12 +35,18 @@ namespace skydiveLogs_api.DomainBusiness
public Aircraft GetAircraftById(int id)
{
return _aircraftRepository.GetById(id);
var allAircrafts = GetAllAircrafts();
return allAircrafts.Single(g => g.Id == id);
}
public IEnumerable<Aircraft> GetAllAircrafts()
{
return _aircraftRepository.GetAll();
if (!_cacheService.Contains(CacheType.Aircraft))
_cacheService.Put(CacheType.Aircraft,
_aircraftRepository.GetAll(),
5 * 60 * 1000);
return _cacheService.Get<IEnumerable<Aircraft>>(CacheType.Aircraft);
}
public void UpdateAircraft(int id, Aircraft aircraft)
@@ -40,6 +54,13 @@ namespace skydiveLogs_api.DomainBusiness
throw new NotImplementedException();
}
#endregion Public Methods
#region Private Fields
private readonly IAircraftRepository _aircraftRepository;
private readonly ICacheService _cacheService;
#endregion Private Fields
}
}
}