Skip to content
This repository was archived by the owner on Sep 4, 2020. It is now read-only.

Commit 5ba34d9

Browse files
author
Caitlin Bales (MSFT)
authored
Merge pull request #50 from sbolotovms/master
Set useCaches to control caching response from server.
2 parents 6870d8f + 1320795 commit 5ba34d9

File tree

7 files changed

+102
-2
lines changed

7 files changed

+102
-2
lines changed

graphsdk/src/androidTest/java/com/microsoft/graph/http/MockHttpRequest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class MockHttpRequest implements IHttpRequest {
2020
private HttpMethod mHttpMethod = HttpMethod.GET;
2121
private List<HeaderOption> mHeaders = new ArrayList<HeaderOption>();
2222
private List<Option> mOptions = new ArrayList<Option>();
23+
private boolean mUseCaches;
2324

2425
@Override
2526
public URL getRequestUrl() {
@@ -47,10 +48,20 @@ public List<Option> getOptions() {
4748

4849
@Override
4950
public void addHeader(String header, String value) {
50-
mHeaders.add(new HeaderOption(header,value));
51+
mHeaders.add(new HeaderOption(header, value));
5152
}
5253

53-
public void setHttpMethod(HttpMethod method){
54+
@Override
55+
public void setUseCaches(boolean useCaches) {
56+
mUseCaches = useCaches;
57+
}
58+
59+
@Override
60+
public boolean getUseCaches() {
61+
return mUseCaches;
62+
}
63+
64+
public void setHttpMethod(HttpMethod method) {
5465
mHttpMethod = method;
5566
}
5667
}

graphsdk/src/androidTest/java/com/microsoft/graph/http/MockRequest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,14 @@ public List<Option> getOptions() {
6262
@Override
6363
public void addHeader(final String header, final String value) {
6464
}
65+
66+
@Override
67+
public void setUseCaches(boolean useCaches) {
68+
// Don't set it for Mock request.
69+
}
70+
71+
@Override
72+
public boolean getUseCaches() {
73+
return false;
74+
}
6575
}

graphsdk/src/main/java/com/microsoft/graph/http/BaseCollectionRequest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,26 @@ public void addHeader(final String header, final String value) {
144144
mBaseRequest.addHeader(header, value);
145145
}
146146

147+
/**
148+
* Sets useCaches parameter to cache the response.
149+
*
150+
* @param useCaches The value of useCaches.
151+
*/
152+
@Override
153+
public void setUseCaches(boolean useCaches) {
154+
mBaseRequest.setUseCaches(useCaches);
155+
}
156+
157+
/**
158+
* Gets useCaches parameter.
159+
*
160+
* @return The value of useCaches.
161+
*/
162+
@Override
163+
public boolean getUseCaches() {
164+
return mBaseRequest.getUseCaches();
165+
}
166+
147167
/**
148168
* Gets the full list of options for this request.
149169
*

graphsdk/src/main/java/com/microsoft/graph/http/BaseRequest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ public abstract class BaseRequest implements IHttpRequest {
9191
*/
9292
private final Class mResponseClass;
9393

94+
/**
95+
* Value to pass to setUseCaches in connection.
96+
*/
97+
private boolean mUseCaches;
98+
9499
/**
95100
* Create the request.
96101
*
@@ -209,6 +214,26 @@ public void addHeader(final String header, final String value) {
209214
mHeadersOptions.add(new HeaderOption(header, value));
210215
}
211216

217+
/**
218+
* Sets useCaches parameter to cache the response.
219+
*
220+
* @param useCaches The value of useCaches.
221+
*/
222+
@Override
223+
public void setUseCaches(boolean useCaches) {
224+
mUseCaches = useCaches;
225+
}
226+
227+
/**
228+
* Gets useCaches parameter.
229+
*
230+
* @return The value of useCaches.
231+
*/
232+
@Override
233+
public boolean getUseCaches() {
234+
return mUseCaches;
235+
}
236+
212237
/**
213238
* Sends this request.
214239
*

graphsdk/src/main/java/com/microsoft/graph/http/BaseStreamRequest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,26 @@ public void addHeader(final String header, final String value) {
136136
mBaseRequest.addHeader(header, value);
137137
}
138138

139+
/**
140+
* Sets useCaches parameter to cache the response.
141+
*
142+
* @param useCaches The value of useCaches.
143+
*/
144+
@Override
145+
public void setUseCaches(boolean useCaches) {
146+
mBaseRequest.setUseCaches(useCaches);
147+
}
148+
149+
/**
150+
* Gets useCaches parameter.
151+
*
152+
* @return The value of useCaches.
153+
*/
154+
@Override
155+
public boolean getUseCaches() {
156+
return mBaseRequest.getUseCaches();
157+
}
158+
139159
/**
140160
* Gets the headers.
141161
*

graphsdk/src/main/java/com/microsoft/graph/http/IHttpRequest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,17 @@ public interface IHttpRequest {
6363
* @param value The value of the header.
6464
*/
6565
void addHeader(String header, String value);
66+
67+
/**
68+
* Sets useCaches parameter to cache the response.
69+
* @param useCaches The value of useCaches.
70+
*/
71+
void setUseCaches(boolean useCaches);
72+
73+
/**
74+
* Gets useCaches parameter.
75+
* @return The value of useCaches.
76+
*/
77+
boolean getUseCaches();
6678
}
6779

graphsdk/src/main/java/com/microsoft/graph/http/UrlConnection.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public UrlConnection(final IHttpRequest request) throws IOException {
6060
mConnection.addRequestProperty(header.getName(), header.getValue());
6161
}
6262

63+
mConnection.setUseCaches(request.getUseCaches());
64+
6365
try {
6466
mConnection.setRequestMethod(request.getHttpMethod().toString());
6567
} catch (final ProtocolException ignored) {

0 commit comments

Comments
 (0)