ASP.Net核心PWA缓存查询

问题描述 投票:1回答:1

Asp.Net 2.2的核心。 MVC应用程序我正努力变成使用的Mads克里斯滕森的WebEssentials.AspNetCore.PWA包https://github.com/madskristensen/WebEssentials.AspNetCore.ServiceWorker逐行Web应用程序(PWA),我有一些问题,以确保某些页面脱机工作。

该应用的主要功能涉及一系列的问题被提出来与保存到数据库的响应用户。该视图是由查询数据库以显示正确的信息的视图模型填充。

我的问题是,作为数据库的内容很少会改变,我能够缓存查询结果,以便在整个应用程序可以离线工作?如果是这样,什么是这样做的最佳做法是什么?

我的默认地图的路线是控制器/操作/ ID,所以当试图利用routesToPreCache在appsettings.json我不能包括新创建的“事件”,所以它不工作的ID - 我缺少一个简单的技巧或者说是解决方案复杂得多?

我的视图控制器如下:

public class PathwayController : Controller
{
    private readonly ApplicationDbContext _context;

    public PathwayController(ApplicationDbContext context)
    {
        _context = context;
    }

    public ActionResult Pathway(int? id, int? index)
    {
        int currentIndex = index.GetValueOrDefault();
        if (currentIndex == 0)
        {
            ViewBag.NextIndex = 1;
        }
        else
        {
            ViewBag.NextIndex = index + 1;
        }

        PathwayViewModel path = new PathwayViewModel();
        var incident = _context.Incident
            .Include(i => i.IncidentType)
            .FirstOrDefault(m => m.Id == id);
        path.Incident = incident;
        var stageConditions = _context.StageCondition.Where(x => x.IncidentTypeId == incident.IncidentTypeId)
            .Include(s => s.Stage)
            .Include(o => o.Stage.Outcome)
            .OrderBy(x => x.Id)
            .Skip(currentIndex)
            .Take(1)
            .FirstOrDefault();

        path.StageCondition = stageConditions;

        // Validation
        var stageConditionTest = _context.StageCondition.Where(x => x.IncidentTypeId == incident.IncidentTypeId);

        ViewBag.MaxIndex = stageConditionTest.Count();

        //save stage to incident
        incident.StageId = stageConditions.Stage.Id;

        _context.Update(incident);
        _context.SaveChanges();

        return View(path);
    }
c# asp.net-core progressive-web-apps
1个回答
0
投票

你想要做什么可以做得到。然而,这将需要“繁重”适量

MADS PWA实用的伟大工程,但它确实有点保护你从服务人员和清单文件。

你需要设置清单缓存“的问题”页面。这将告诉PWA继续前进,在用户的设备上自动缓存的页面,而用户曾经访问过它。当他们脱机方式,它会出现,当他们最终浏览到该页面。

但是,如果用户不在线,用户提交的数据包括两个方面:存储响应值到本地存储(不太难),然后通过触发事件同步了用户的浏览器本地存储,当设备在线,然后这些数据发送到远程(你的)数据库(而参与其中,因此很难)。

希望帮助。

© www.soinside.com 2019 - 2024. All rights reserved.