Example #1
0
def fileCacheRefresh(f, sha):
    # Load yaml data from file.
    data = yaml.load(urlfetch.fetch(raw_path + f).content)

    # Format the data to be saved in the database
    data_json = json.dumps(data, separators=(',', ':'))

    # Attempt to load the record
    fc = FileCache.gql('WHERE project = :1', f).get()

    if fc:  # Save data to existing record
        fc.sha = sha
        fc.data = data_json
        fc.put()
    else:  # Create a new record
        fc = FileCache(filename=f, sha=sha, data=data_json)
        fc.put()

    return data
Example #2
0
def fileGet(f, sha):
    fc = FileCache.gql('WHERE filename = :1', f).get()

    if fc:
        if sha == fc.sha:
            logging.info('file unchanged, using cache.')
            return (False, json.loads(fc.data))
        else:
            logging.info('file changed, refreshing cache.')
            return (True, fileCacheRefresh(f, sha))
    else:
        logging.info('file not in cache, retrieving.')
        return (True, fileCacheRefresh(f, sha))