Skip to content

Reading file's content through GHContent.read() returns previous version of file. #487

@BrunoMNDantas

Description

@BrunoMNDantas

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:

  1. Read any file's content.
  2. Update file and write something different on it.
  3. Read file's content again.
  4. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions