3 * Copyright 2019 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #import <GRPCClient/GRPCInterceptor.h>
21 NS_ASSUME_NONNULL_BEGIN
23 @interface RequestCacheEntry : NSObject<NSCopying>
25 @property(readonly, copy, nullable) NSString *path;
26 @property(readonly, copy, nullable) id message;
30 @interface MutableRequestCacheEntry : RequestCacheEntry
32 @property(copy, nullable) NSString *path;
33 @property(copy, nullable) id<NSObject> message;
37 @interface ResponseCacheEntry : NSObject<NSCopying>
39 @property(readonly, copy, nullable) NSDate *deadline;
41 @property(readonly, copy, nullable) NSDictionary *headers;
42 @property(readonly, copy, nullable) id message;
43 @property(readonly, copy, nullable) NSDictionary *trailers;
47 @interface MutableResponseCacheEntry : ResponseCacheEntry
49 @property(copy, nullable) NSDate *deadline;
51 @property(copy, nullable) NSDictionary *headers;
52 @property(copy, nullable) id message;
53 @property(copy, nullable) NSDictionary *trailers;
57 @interface CacheContext : NSObject<GRPCInterceptorFactory>
59 - (nullable instancetype)init;
61 - (nullable ResponseCacheEntry *)getCachedResponseForRequest:(RequestCacheEntry *)request;
63 - (void)setCachedResponse:(ResponseCacheEntry *)response forRequest:(RequestCacheEntry *)request;
67 @interface CacheInterceptor : GRPCInterceptor
69 - (instancetype)init NS_UNAVAILABLE;
71 + (instancetype) new NS_UNAVAILABLE;
73 - (nullable instancetype)initWithInterceptorManager:
74 (GRPCInterceptorManager *_Nonnull)intercepterManager
75 cacheContext:(CacheContext *_Nonnull)cacheContext
76 NS_DESIGNATED_INITIALIZER;
78 // implementation of GRPCInterceptorInterface
79 - (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions
80 callOptions:(GRPCCallOptions *)callOptions;
81 - (void)writeData:(id)data;
84 // implementation of GRPCResponseHandler
85 - (void)didReceiveInitialMetadata:(nullable NSDictionary *)initialMetadata;
86 - (void)didReceiveData:(id)data;
87 - (void)didCloseWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata
88 error:(nullable NSError *)error;