Comments (3)
That would be pretty tricky to implement because it would essentially break the entire downloader pipeline.
Right now, each request is run through each RequestMiddleware
first, so that any middleware can alter or drop the request before it gets sent. Then, the response is passed through each ResponseMiddleware
. Adding a kind of middleware that takes a request and immediately returns a response would completely break this pattern, unfortunately.
A possible way to deal with this could be, extending the Request
class to allow setting a Response
on the request. The downloader could then check if the request already has a response set and simply return that response instead of sending the request. I think this is similar to how Symfony's kernel events work, too.
You could then implement a caching middleware by simply setting the cached response on the request inside a regular RequestMiddleware
. The hypothetical API could look something like this:
class CachingMiddleware implements RequestMiddlewareInterface
{
public function handleRequest(Request $request): Request
{
// assuming the cache returns `null` if no cached response exists, it's safe
// to always set the result of `forRequest` on the request.
$cachedResponse = $this->cache->forRequest($request);
return $request->setResponse($cachedResponse);
}
}
This would still allow the other middlewares to run as usual which is something I definitely want to preserve.
from core.
That's a great way of doing it, i'll work on adding that, Thanks!
from core.
Related Issues (20)
- Run namespace and Request serialization HOT 2
- Is there a documented way to scrape Single Page Applications? HOT 1
- Is there any way of accessing the first item inside a processor or an extension? HOT 2
- No publishable resources for tag [] for publishing config file HOT 2
- Pass Context into Request Middleware HOT 3
- This library is no longer maintained? HOT 2
- Possibly to scrape behind secured sessions
- Self signed certificate HOT 2
- How to process items in batch?
- Laravel 10 support? HOT 1
- No results with specific url HOT 2
- Argument #1 ($timestamp) must be greater than or equal to the current time HOT 1
- How to login and then scrap data from a page that requires auth? HOT 1
- time_sleep_until(): Argument #1 ($timestamp) must be greater than or equal to the current time HOT 4
- Responses dropped by middlewares are not registered HOT 1
- parse method is called even on response status 404 HOT 2
- Requests with ExecuteJavascriptMiddleware are sent twice HOT 1
- Conflict with Laravel 9 HOT 2
- Symfony 5.4.1 issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.