Windows service worker download files
An origin can have multiple named Cache objects. To create a cache or open a connection to an existing cache we use the caches. This returns a promise that resolves to the cache object. The Cache API comes with several methods that let us create and manipulate data in the cache.
These can be grouped into methods that either create, match, or delete data. There are three methods we can use to add data to the cache. These are add , addAll , and put. In practice, we will call these methods on the cache object returned from caches. For example:. We call the add method on this object to add the file to that cache.
The key for that object will be the request, so we can retrieve this response object again later by this request. If any of the files fail to be added to the cache, the whole operation will fail and none of the files will be added. This lets you manually insert the response object.
Often, you will just want to fetch one or more requests and then add the result straight to your cache. In such cases you are better off just using cache. There are a couple of methods to search for specific content in the cache: match and matchAll. These can be called on the caches object to search through all of the existing caches, or on a specific cache returned from caches. It returns undefined if no match is found. The first parameter is the request, and the second is an optional list of options to refine the search.
Here are the options as defined by MDN:. For example, if your app has cached some images contained in an image folder, we could return all images and perform some operation on them like this:. We can delete items in the cache with cache.
This method finds the item in the cache matching the request, deletes it, and returns a Promise that resolves to true. If it doesn't find the item, it resolves to false.
It also has the same optional options parameter available to it as the match method. Finally, we can get a list of cache keys using cache. This returns a Promise that resolves to an array of cache keys. These will be returned in the same order they were inserted into the cache. Both parameters are optional. You can specify a folder that already contains user data, which enables you to adopt Work Folders without migrating servers and data or immediately phasing out your existing solution.
Administrators can use Work Folders to provide users with access to their work files while keeping centralized storage and control over the organization's data. Some specific applications for Work Folders include:. Provide a single point of access to work files from a user's work and personal computers and devices. Access work files while offline, and then sync with the central file server when the PC or device next has Internet or intranet connectivity. Use existing file server management technologies, such as file classification and folder quotas, to manage user data.
Specify security policies to instruct user's PCs and devices to encrypt Work Folders and use a lock screen password. Windows 8. Work Folders has the following software requirements for file servers and your network infrastructure:. A server certificate for each file server that will host Work Folders.
These certificates should be from a certification authority CA that is trusted by your users—ideally a public CA. Optional An Active Directory Domain Services forest with the schema extensions in Windows Server R2 to support automatically referring PCs and devices to the correct file server when using multiple file servers.
The ability to make a server accessible from the Internet by creating publishing rules in your organization's reverse proxy or network gateway. Optional A publicly registered domain name and the ability to create additional public DNS records for the domain.
Windows 7 PCs must be joined to your organization's domain they can't be joined to a workgroup. Enough free space on a local, NTFS-formatted drive to store all the user's files in Work Folders, plus an additional 6 GB of free space if Work Folders is located on the system drive, as it is by default. In other terms, should they be considered as dependent on each other, or not? If run in parallel, should they be batched to prevent a bottleneck on the network?
In case the network is considered available, but the requests still fail for some reason, which retry logic to implement? Exponential backoff? How to notify the user that their actions are in a pending state while they are?
This is really very broad for a single StackOverflow answer. Guerric P Guerric P Thank you, very much, for your experimentation and explanation. I still wonder about the Cache API though.
Can't we do something like cache. In other words, take the request body the file , and cache it for future GET requests by making a new response like we'd like to see for future GET requests. As for your other points, you're right in that they are important, but I don't think they're necessary to address for the purpose of this question. Example code can be left as simple as possible to work.
Thanks for your feedback, I will provide a minimal solution soon — Guerric P. You're making assumptions based on errors that come from server responses. You're trying to request a single page 50x. Check this repo that I include in my answer to see an expressjs server which can handle all these requests. ChristosLytras actually, these errors are not related to my backend, but to the cache implementation: chromium.
GuerricP Thanks again for your answer. I'm awarding your answer a bounty as well as the other answer, but Stack Overflow says I have to wait a few days, so I'll come back to it. Show 5 more comments. Luca Pizzini 2, 1 1 gold badge 3 3 silver badges 19 19 bronze badges. Arulvel Arulvel 39 2 2 bronze badges.
Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.
Email Required, but never shown. The Overflow Blog. UseWindowsService after the Host. CreateDefaultBuilder args , so that you end up with the following in your program.
In the worker. This will be used to access the appsettings configuration file. To make sure that configurations are read every time the service is started, I override the method StartAsync and retrieve my application configurations here:. Our code for retrieving folders from our configuration file and remove all files older than 90 days will be placed in the method ExecuteAsync.
ExecuteAsync takes a CancellationToken as a parameter. The CancellationToken is very important because it will be used to identify when the service is stopped. When this happens, the property IsCancellationRequested will be set to true. Hence, the first line of code in our ExecuteAsync is:. I will do a second check for IsCancellationRequested in this method further down to make sure that I stop the execution as quickly as possible when receiving a cancellation request.