RouteCache class

A specialized route that handles caching of HTTP responses.

It extends FinchRoute to intercept the route handling and serve cached responses if they exist and are not expired.

Inheritance
Available extensions

Constructors

RouteCache({required String path, required Future<String> handle(), Duration cacheDuration = const Duration(minutes: 10), List<CacheParam> cacheType = const [CacheParam.method, CacheParam.path, CacheParam.language], CacheSource cacheSource = CacheSource.memory, String? key, List<String> extraPath = const [], List<String> methods = const [Methods.GET], Controller? controller, String widget = "", AuthController? auth, List<FinchRoute> children = const [], Map<String, Object?> params = const {}, String title = '', List<String> excludePaths = const [], Future<ApiDoc>? apiDoc()?, List<String> permissions = const [], List<String> hosts = const ['*'], List<int> ports = const [], List<Middleware> middlewares = const []})
Creates a new RouteCache instance.

Properties

apiDoc Future<ApiDoc>? Function()?
Function to generate API documentation for this route.
getter/setter pairinherited
auth AuthController?
An optional AuthController for handling authentication and session checks for this route.
getter/setter pairinherited
cacheDuration Duration
The duration for which a cache entry remains valid.
getter/setter pair
cacheSource CacheSource
The storage medium where cache will be saved.
getter/setter pair
cacheType List<CacheParam>
A list of CacheParams used to build the unique cache key.
getter/setter pair
children List<FinchRoute>
Sub-routes of the current route, defining a tree structure of routes.
getter/setter pairinherited
controller Controller?
The controller associated with this route. This is an instance of Controller that will handle the request for this route.
getter/setter pairinherited
excludePaths List<String>
Paths that should not be included in all sub-paths of /*.
getter/setter pairinherited
extraPath List<String>
Additional main paths for this route. This allows for multiple matching paths.
getter/setter pairinherited
handle Future<String> Function()
The asynchronous handler function that generates the response.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
hosts List<String>
The primary hostname constraints for this route.
getter/setter pairinherited
index Future<String> Function()?
A function representing the main controller function to load for this route. This is typically used to render the index of the controller.
getter/setter pairinherited
key String?
Key of routes of the current route, defining a tree structure of routes.
getter/setter pairinherited
methods List<String>
List of HTTP methods allowed for this route. For example, POST, GET, HEAD, etc.
getter/setter pairinherited
middlewares List<Middleware>
getter/setter pairinherited
params Map<String, Object?>
Default variable parameters to use in the content.
getter/setter pairinherited
parent FinchRoute?
getter/setter pairinherited
path String
The primary path of the route. For example, /test or /test/*. If using /test/*, it will match all sub-paths under /test.
getter/setter pairinherited
permissions List<String>
Permissions required for this route. Authentication is needed to use these permissions.
getter/setter pairinherited
ports List<int>
The port number constraints for this route.
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
title String
The title of the page, which can be used as {{ $e.pageTitle }}.
getter/setter pairinherited
widget String
Path to the widget to be loaded as content for this route.
getter/setter pairinherited

Methods

allowMethod() bool
Validates if the current HTTP request method is allowed for this route.
inherited
cache({Duration cacheDuration = const Duration(minutes: 10), List<CacheParam> cacheType = const [CacheParam.method, CacheParam.path], CacheSource cacheSource = CacheSource.memory}) RouteCache

Available on FinchRoute, provided by the FinchRouteExtension extension

Wraps the current FinchRoute with a RouteCache to enable response caching.
existCache(String key) bool
Checks if a cache entry exists for the given key.
getFullPath() String
inherited
getPathRender() String
Gets the path after rendering.
inherited
getUrl([Map<String, Object?> params = const {}, Map<String, Object?> queries = const {}]) String
inherited
handleMiddlewares() Future<bool>
inherited
middleware(Middleware middleware) FinchRoute
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
readCache(String key) Cache?
Retrieves the cached response for the given key.
removeCache(String key) → void
Removes the cache entry associated with the given key.
setCache(String key, Cache cache) → void
Stores a cache entry for the specified key.
setPathRender(String path) → void
Sets the rendered path for this route.
inherited
toDetails() Map<String, Object?>
inherited
toMap(String parentPath, bool hasAuth, String method) List<Map>
Converts the route to a list of maps representing its details.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

clearAllCache() Future<void>
Clears all existing cache entries from both memory and file system.