Implement an Optional Caching Layer for Use with Any Remote Stream

Created on 23 December 2020, almost 4 years ago
Updated 10 February 2024, 10 months ago

Problem/Motivation

In our project, we are requesting audio and video files from a remote endpoint through Remote Stream Wrapper. We find that this results in 3-5 requests for the full file from the remote system each time a web browser requests such a file through Drupal. This is especially bad in browsers like Safari which demand to be able to use "ranged requests" in order to buffer their content, since Drupal has to request the full file from the remote system for each partial seek-and-read request.

It would be great if this module provided a way to cache these files locally for a short time so that we can avoid unnecessary round-trips to the remote system.

Steps to reproduce

  1. Create a new request controller in Drupal (i.e. in a custom module) that serves up remote A/V files through Remote Stream Wrapper.
  2. Use a \Symfony\Component\HttpFoundation\BinaryFileResponse in your controller method so that the response handles RFC 2616 (aka "range requests", like the ones Safari demands) properly.

Proposed resolution

Implement a new stream wrapper that composes/decorates the existing HttpStreamWrapper wrapper with one that automatically caches requested files in the Drupal temporary file system. Ensure that these temporary files get registered as FILE_STATUS_TEMPORARY with the managed file system in Drupal so they get garbage collected periodically (e.g. every four hours).

Remaining tasks

User interface changes

None.

API changes

None (the change is additive and does not affect existing consumers of the HTTP stream wrapper).

Data model changes

None.

✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States GuyPaddock

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024