apifrom.performance.request_coalescingο
Request coalescing module for APIFromAnything.
This module provides functionality to coalesce multiple identical requests into a single request, reducing the load on backend services and improving performance.
Overviewο
Classes
Functions
Classesο
Represents a coalesced request.
This class is used to track multiple identical requests that have been coalesced into a single request.
Initialize a coalesced request.
- param key:
Cache key for the request.
- type key:
str
- param func:
Function to execute.
- type func:
Callable
- param args:
Positional arguments for the function.
- type args:
tuple
- param kwargs:
Keyword arguments for the function.
- type kwargs:
dict
- apifrom.performance.request_coalescing.execute()ο
Execute the request.
- returns:
Result of executing the function.
- rtype:
Any
- class apifrom.performance.request_coalescing.RequestCoalescer(func, window_time=0.1, max_requests=None)[source]ο
Coalescer for handling duplicate requests.
This class provides functionality to coalesce multiple identical requests into a single request, reducing the load on backend services and improving performance.
Initialize the request coalescer.
- param func:
Function to execute.
- type func:
Callable
- param window_time:
Time window in seconds to coalesce requests.
- type window_time:
float
- param max_requests:
Maximum number of requests to coalesce.
- type max_requests:
int, optional
- apifrom.performance.request_coalescing._create_key(args, kwargs)ο
Create a cache key from the arguments.
- param args:
Positional arguments.
- param kwargs:
Keyword arguments.
- returns:
Cache key.
- rtype:
str
- apifrom.performance.request_coalescing.get_stats()ο
Get statistics about the coalescer.
- returns:
Statistics about the coalescer.
- rtype:
dict
Manager for coalescing requests across the application.
This class provides a centralized way to manage request coalescing across the application.
Initialize the request coalescing manager.
- apifrom.performance.request_coalescing.execute(func, *args, **kwargs)ο
Execute a request, potentially coalescing it with other identical requests.
- param func:
Function to execute.
- type func:
Callable
- param *args:
Positional arguments for the function.
- param **kwargs:
Keyword arguments for the function.
- returns:
Result of executing the function.
- rtype:
Any
- apifrom.performance.request_coalescing.get_coalescer(func, window_time=0.1, max_requests=None)ο
Get or create a coalescer for a function.
- param func:
Function to coalesce.
- type func:
Callable
- param window_time:
Time window in seconds to coalesce requests.
- type window_time:
float
- param max_requests:
Maximum number of requests to coalesce.
- type max_requests:
int, optional
- returns:
Coalescer for the function.
- rtype:
RequestCoalescer
- apifrom.performance.request_coalescing.get_stats()ο
Get statistics about the manager.
- returns:
Statistics about the manager.
- rtype:
dict
- class apifrom.performance.request_coalescing.RequestCoalescingMiddleware(window_time=0.1, max_requests=None)[source]ο
Middleware for coalescing requests.
This middleware can be used to coalesce requests at the middleware level.
Initialize the request coalescing middleware.
- param window_time:
Time window in seconds to coalesce requests.
- type window_time:
float
- param max_requests:
Maximum number of requests to coalesce.
- type max_requests:
int, optional
- apifrom.performance.request_coalescing.get_stats()ο
Get statistics about the middleware.
- returns:
Statistics about the middleware.
- rtype:
dict
- apifrom.performance.request_coalescing.process_request(request)ο
Process a request, potentially coalescing it with other identical requests.
- param request:
Request to process.
- type request:
Any
- returns:
Processed request.
- rtype:
Any
- apifrom.performance.request_coalescing.process_response(request, response)ο
Process a response.
- param request:
Request that generated the response.
- type request:
Any
- param response:
Response to process.
- type response:
Any
- returns:
Processed response.
- rtype:
Any
Functionsο
- apifrom.performance.request_coalescing.coalesce_requests(window_time=0.1, max_requests=None)[source]ο
Decorator for coalescing multiple identical requests into a single request.
- param window_time:
Time window in seconds to coalesce requests.
- type window_time:
float
- param max_requests:
Maximum number of requests to coalesce.
- type max_requests:
int, optional
- returns:
Decorated function that coalesces requests.
- rtype:
Callable