File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
Mvc.Abstractions/src/Abstractions Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -75,5 +75,7 @@ public ActionDescriptor()
75
75
/// Stores arbitrary metadata properties associated with the <see cref="ActionDescriptor"/>.
76
76
/// </summary>
77
77
public IDictionary < object , object > Properties { get ; set ; } = default ! ;
78
+
79
+ internal IFilterMetadata [ ] ? CachedResuableFilters { get ; set ; }
78
80
}
79
81
}
Original file line number Diff line number Diff line change @@ -46,15 +46,24 @@ public static FilterFactoryResult GetAllFilters(
46
46
// Cache the filter items based on the following criteria
47
47
// 1. Are created statically (ex: via filter attributes, added to global filter list etc.)
48
48
// 2. Are re-usable
49
+ var allFiltersAreReusable = true ;
49
50
for ( var i = 0 ; i < staticFilterItems . Length ; i ++ )
50
51
{
51
52
var item = staticFilterItems [ i ] ;
52
53
if ( ! item . IsReusable )
53
54
{
54
55
item . Filter = null ;
56
+ allFiltersAreReusable = false ;
55
57
}
56
58
}
57
59
60
+ if ( allFiltersAreReusable && filterProviders . Length == 1 && filterProviders [ 0 ] is DefaultFilterProvider defaultFilterProvider )
61
+ {
62
+ // If we know we can safely cache all filters and only the default filter provider is registered, we can
63
+ // probably re-use filters between requests.
64
+ actionDescriptor . CachedResuableFilters = filters ;
65
+ }
66
+
58
67
return new FilterFactoryResult ( staticFilterItems , filters ) ;
59
68
}
60
69
@@ -78,6 +87,11 @@ public static IFilterMetadata[] CreateUncachedFilters(
78
87
throw new ArgumentNullException ( nameof ( cachedFilterItems ) ) ;
79
88
}
80
89
90
+ if ( actionContext . ActionDescriptor . CachedResuableFilters is { } cached )
91
+ {
92
+ return cached ;
93
+ }
94
+
81
95
// Deep copy the cached filter items as filter providers could modify them
82
96
var filterItems = new List < FilterItem > ( cachedFilterItems . Length ) ;
83
97
for ( var i = 0 ; i < cachedFilterItems . Length ; i ++ )
You can’t perform that action at this time.
0 commit comments