While developing my project I've reached a strange behavior when reading files after been updated.
To reproduce the problem we can follow this steps:
- Read any file's content.
- Update file and write something different on it.
- Read file's content again.
- Realize that the content returned on 2nd read is equals to the content returned on 1st read, instead of the value written on update.
I wrote a simple JUnit test to reproduce this problem:
@Test
public void test() throws IOException {
String contentBefore = readFile();
assertEquals("", contentBefore);
String contentWritten = updateFile();
String contentAfter = readFile();
assertEquals(contentWritten, contentAfter);
//This test fails because 'contentAfter' contains same value as 'contentBefore' instead of 'contentWritten'.
//assertEquals(contentBefore, contentAfter);
//This test should fail, but actually, it passes.
}
Complete Test class and gradle file can be found here: https://gist.github.com/BrunoMNDantas/3b0a9af9b03b22861a9b14319a9cc6cf
To read files I'm using GHContent.read().
After some debugging I've realized that read method uses download_url (https://raw.githubusercontent.com/...) property returned by github-api. The problem is that this url seems to have some kind of cache that returns the old version of file for up to 5-10 min after a file been updated.
As a workaround, instead of using GHContent.read() I'm using GHBlob.read().
Am I doing something wrong?
While developing my project I've reached a strange behavior when reading files after been updated.
To reproduce the problem we can follow this steps:
I wrote a simple JUnit test to reproduce this problem:
Complete Test class and gradle file can be found here: https://gist.github.com/BrunoMNDantas/3b0a9af9b03b22861a9b14319a9cc6cf
To read files I'm using GHContent.read().
After some debugging I've realized that read method uses download_url (https://raw.githubusercontent.com/...) property returned by github-api. The problem is that this url seems to have some kind of cache that returns the old version of file for up to 5-10 min after a file been updated.
As a workaround, instead of using GHContent.read() I'm using GHBlob.read().
Am I doing something wrong?