@@ -93,4 +93,78 @@ public static ICacheSpecificationBuilder<T> EnableCache<T>(
93
93
Specification < T > . IsChainDiscarded = ! condition ;
94
94
return ( SpecificationBuilder < T > ) builder ;
95
95
}
96
+
97
+ /// <summary>
98
+ /// Sets the cache key for the specification.
99
+ /// </summary>
100
+ /// <typeparam name="T">The type of the entity.</typeparam>
101
+ /// <typeparam name="TResult">The type of the result.</typeparam>
102
+ /// <param name="builder">The specification builder.</param>
103
+ /// <param name="cacheKey">The cache key to be used.</param>
104
+ /// <returns>The updated ordered specification builder.</returns>
105
+ /// <exception cref="ArgumentException">If specificationName is null or empty.</exception>
106
+ public static ICacheSpecificationBuilder < T , TResult > WithCacheKey < T , TResult > (
107
+ this ISpecificationBuilder < T , TResult > builder ,
108
+ string cacheKey ) where T : class
109
+ => WithCacheKey ( builder , cacheKey , true ) ;
110
+
111
+ /// <summary>
112
+ /// Sets the cache key for the specification.
113
+ /// </summary>
114
+ /// <typeparam name="T">The type of the entity.</typeparam>
115
+ /// <typeparam name="TResult">The type of the result.</typeparam>
116
+ /// <param name="builder">The specification builder.</param>
117
+ /// <param name="cacheKey">The cache key to be used.</param>
118
+ /// <param name="condition">The condition to evaluate.</param>
119
+ /// <returns>The updated ordered specification builder.</returns>
120
+ /// <exception cref="ArgumentException">If specificationName is null or empty.</exception>
121
+ public static ICacheSpecificationBuilder < T , TResult > WithCacheKey < T , TResult > (
122
+ this ISpecificationBuilder < T , TResult > builder ,
123
+ string cacheKey ,
124
+ bool condition ) where T : class
125
+ {
126
+ if ( condition )
127
+ {
128
+ builder . Specification . CacheKey = cacheKey ;
129
+ }
130
+
131
+ Specification < T , TResult > . IsChainDiscarded = ! condition ;
132
+ return ( SpecificationBuilder < T , TResult > ) builder ;
133
+ }
134
+
135
+ /// <summary>
136
+ /// Sets the cache key for the specification.
137
+ /// </summary>
138
+ /// <typeparam name="T">The type of the entity.</typeparam>
139
+ /// <param name="builder">The specification builder.</param>
140
+ /// <param name="cacheKey">The cache key to be used.</param>
141
+ /// <returns>The updated ordered specification builder.</returns>
142
+ /// <exception cref="ArgumentException">If specificationName is null or empty.</exception>
143
+ public static ICacheSpecificationBuilder < T > WithCacheKey < T > (
144
+ this ISpecificationBuilder < T > builder ,
145
+ string cacheKey ) where T : class
146
+ => WithCacheKey ( builder , cacheKey , true ) ;
147
+
148
+ /// <summary>
149
+ /// Sets the cache key for the specification.
150
+ /// </summary>
151
+ /// <typeparam name="T">The type of the entity.</typeparam>
152
+ /// <param name="builder">The specification builder.</param>
153
+ /// <param name="cacheKey">The cache key to be used.</param>
154
+ /// <param name="condition">The condition to evaluate.</param>
155
+ /// <returns>The updated ordered specification builder.</returns>
156
+ /// <exception cref="ArgumentException">If specificationName is null or empty.</exception>
157
+ public static ICacheSpecificationBuilder < T > WithCacheKey < T > (
158
+ this ISpecificationBuilder < T > builder ,
159
+ string cacheKey ,
160
+ bool condition ) where T : class
161
+ {
162
+ if ( condition )
163
+ {
164
+ builder . Specification . CacheKey = cacheKey ;
165
+ }
166
+
167
+ Specification < T > . IsChainDiscarded = ! condition ;
168
+ return ( SpecificationBuilder < T > ) builder ;
169
+ }
96
170
}
0 commit comments