infrastructure for dealing with client cache invalidation in a multi-user environment
This commit is contained in:
44
Oqtane.Server/Infrastructure/SyncManager.cs
Normal file
44
Oqtane.Server/Infrastructure/SyncManager.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Repository;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Oqtane.Infrastructure
|
||||
{
|
||||
public class SyncManager : ISyncManager
|
||||
{
|
||||
private readonly IServiceScopeFactory ServiceScopeFactory;
|
||||
private List<SyncEvent> SyncEvents { get; set; }
|
||||
|
||||
public SyncManager(IServiceScopeFactory ServiceScopeFactory)
|
||||
{
|
||||
this.ServiceScopeFactory = ServiceScopeFactory;
|
||||
SyncEvents = new List<SyncEvent>();
|
||||
}
|
||||
|
||||
private int TenantId
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
return scope.ServiceProvider.GetRequiredService<ITenantResolver>().GetTenant().TenantId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<SyncEvent> GetSyncEvents(DateTime LastSyncDate)
|
||||
{
|
||||
return SyncEvents.Where(item => item.TenantId == TenantId && item.ModifiedOn >= LastSyncDate).ToList();
|
||||
}
|
||||
|
||||
public void AddSyncEvent(string EntityName, int EntityId)
|
||||
{
|
||||
SyncEvents.Add(new SyncEvent { TenantId = TenantId, EntityName = EntityName, EntityId = EntityId, ModifiedOn = DateTime.Now });
|
||||
// trim sync events
|
||||
SyncEvents.RemoveAll(item => item.ModifiedOn < DateTime.Now.AddHours(-1));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user