{"size": 573, "ext": "js", "max_stars_repo_path": "src/cache/FsCacheProvider.js", "max_stars_repo_name": "tylerhaun/image-transformation-service", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/cache/FsCacheProvider.js", "max_issues_repo_name": "tylerhaun/image-transformation-service", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/cache/FsCacheProvider.js", "max_forks_repo_name": "tylerhaun/image-transformation-service", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 18.4838709677, "max_line_length": 61, "alphanum_fraction": 0.6143106457}
const FsProvider = require("../shared-providers/FsProvider");


const defaultPath = "cache";


class FsCacheProvider {

  constructor() {
    const path = process.env.FS_CACHE_PATH || defaultPath;
    this.fsProvider = new FsProvider({path});
  }

  async get(key) {
    return this.fsProvider.read(key)
      .catch(error => {
        if (error.errno == -2) { // no such file or directory
          return null;
        }
        throw error;
      });
  }

  async set(key, value) {
    return this.fsProvider.write(key, value);
  }

}

module.exports = FsCacheProvider;
