Skip to content

Commit 8a1b74a

Browse files
committed
Remvoe ParseFile in-memory cache
1 parent a9de8df commit 8a1b74a

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

Parse/src/main/java/com/parse/ParseFile.java

+5-13
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ public boolean isDirty() {
295295
* Whether the file has available data.
296296
*/
297297
public boolean isDataAvailable() {
298+
// TODO(mengyan): Revise when we have proper stage strategy for file pointer
298299
return data != null || getFileController().isDataAvailable(state);
299300
}
300301

@@ -389,6 +390,9 @@ public Task<Void> then(Task<String> task) throws Exception {
389390
public Task<Void> then(Task<Void> task) throws Exception {
390391
cts.trySetResult(null); // release
391392
currentTasks.remove(cts);
393+
// Clear in memory file pointer and data
394+
data = null;
395+
file = null;
392396
return task;
393397
}
394398
});
@@ -453,30 +457,18 @@ public byte[] getData() throws ParseException {
453457
* @return A Task that is resolved when the data has been fetched.
454458
*/
455459
public Task<byte[]> getDataInBackground(final ProgressCallback progressCallback) {
456-
// If data is already available, just return immediately.
457-
if (data != null) {
458-
// in-memory
459-
return Task.forResult(data);
460-
}
461-
462460
final Task<Void>.TaskCompletionSource cts = Task.create();
463461
currentTasks.add(cts);
464462

465463
return taskQueue.enqueue(new Continuation<Void, Task<byte[]>>() {
466464
@Override
467465
public Task<byte[]> then(Task<Void> toAwait) throws Exception {
468-
// If data is already available, just return immediately.
469-
if (data != null) {
470-
// in-memory
471-
return Task.forResult(data);
472-
}
473-
474466
return fetchInBackground(progressCallback, toAwait, cts.getTask()).onSuccess(new Continuation<File, byte[]>() {
475467
@Override
476468
public byte[] then(Task<File> task) throws Exception {
477469
File file = task.getResult();
478470
try {
479-
data = ParseFileUtils.readFileToByteArray(file);
471+
byte[] data = ParseFileUtils.readFileToByteArray(file);
480472
return data;
481473
} catch (IOException e) {
482474
// do nothing

Parse/src/test/java/com/parse/ParseFileTest.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,28 @@ public void testConstructor() throws Exception {
5858
String contentType = "content_type";
5959
File file = temporaryFolder.newFile("test");
6060

61+
// TODO(mengyan): Test data and file pointer in ParseFile when we have proper stage strategy
62+
6163
ParseFile parseFile = new ParseFile(name, data, contentType);
6264
assertEquals("name", parseFile.getName());
63-
assertEquals("hello", new String(parseFile.getData()));
6465
assertEquals("content_type", parseFile.getState().mimeType());
6566
assertTrue(parseFile.isDirty());
6667

6768
parseFile = new ParseFile(data);
6869
assertEquals("file", parseFile.getName()); // Default
69-
assertEquals("hello", new String(parseFile.getData()));
7070
assertEquals(null, parseFile.getState().mimeType());
7171
assertTrue(parseFile.isDirty());
7272

7373
parseFile = new ParseFile(name, data);
7474
assertEquals("name", parseFile.getName());
75-
assertEquals("hello", new String(parseFile.getData()));
7675
assertEquals(null, parseFile.getState().mimeType());
7776
assertTrue(parseFile.isDirty());
7877

7978
parseFile = new ParseFile(data, contentType);
8079
assertEquals("file", parseFile.getName()); // Default
81-
assertEquals("hello", new String(parseFile.getData()));
8280
assertEquals("content_type", parseFile.getState().mimeType());
8381
assertTrue(parseFile.isDirty());
8482

85-
// TODO(mengyan): Test file pointer in ParseFile when we have proper stage strategy
8683
parseFile = new ParseFile(name, file, contentType);
8784
assertEquals("name", parseFile.getName());
8885
assertEquals("content_type", parseFile.getState().mimeType());

0 commit comments

Comments
 (0)