Skip to content

Add support for two level cache - #380

Closed
pavsa wants to merge 1 commit into
ccache:masterfrom
pavsa:master
Closed

pavsa wants to merge 1 commit into
ccache:masterfrom
pavsa:master

Conversation

@pavsa

@pavsa pavsa commented Apr 16, 2019

Copy link
Copy Markdown
Contributor

Would this be any use? I can polish it more if there's an interest to merge it.

cache_dir_l0 is added to configuration.
If set, ccache performs its first lookup from this directory.
If it fails, it does a second lookup in cache_dir and continues as usual.

@jrosdahl

Copy link
Copy Markdown
Member

It's a fine idea, and also an idea has that has come up before. I would like to wait with adding support for multilevel caches like this until I/we have found time to work on generalizing how backends work and how to configure them.

One question though: Why only enable it for the depend mode?

@pavsa

pavsa commented Apr 16, 2019

Copy link
Copy Markdown
Contributor Author

For simple reason: I have not tested it in other modes.

@afbjorklund

afbjorklund commented Apr 16, 2019 •

Copy link
Copy Markdown
Contributor

Probably should call it something else than "multi level cache" too, to avoid confusion with NLEVELS ?

@afbjorklund

Copy link
Copy Markdown
Contributor

@pavsa : how do you transport the files, from "some central compile server" to the L0 cache ?

@pavsa

pavsa commented Apr 17, 2019

Copy link
Copy Markdown
Contributor Author

Probably should call it something else than "multi level cache" too, to avoid confusion with NLEVELS ?

That is a better name :) I admit it is confusing with the NLEVELS. Everything can be renamed in the end.

@pavsa : how do you transport the files, from "some central compile server" to the L0 cache ?
By rsync.

@afbjorklund

Copy link
Copy Markdown
Contributor

I don't think this feature has anything to do with depend mode, so that part can probably be dropped...

We used a similar approach for cache located on NFS, when people were scared of using memcached.
Basically the only difference was that files were copied from the central cache, over to the local server.

The main reason for this is that you wanted to get local hits next time, if you built the same thing again.

@jrosdahl jrosdahl changed the title Add support for two level cache in depend mode. Add support for two level cache Apr 29, 2019
cache_dir_l0 is added to configuration.
If set, ccache performs its first lookup from this directory.
If it fails, it does a second lookup in *cache_dir* and continues as usual.
@klimkin

klimkin commented May 7, 2019

Copy link
Copy Markdown

I would love to have this feature! This way we can set level-0 to our CI cache to speedup builds after new code pulls.

@megabyde

Copy link
Copy Markdown

Any updates on this feature? This would greatly improve caching experience in shared environment with nightly CI builds.

@pavsa

pavsa commented Jan 28, 2021

Copy link
Copy Markdown
Contributor Author

Any updates on this feature? This would greatly improve caching experience in shared environment with nightly CI builds.

Well it works as is, so you can use it as is with older branch as I still do.
Until the API discussion is resolved, this is as good as it gets.

@afbjorklund

Copy link
Copy Markdown
Contributor

There is a simple FileBackend for the StorageBackend, that will accomplish this:

#414 (comment)

bool
FileBackend::put(const std::string& url, const std::string& path)
{
  try {
    Util::copy_file(path, url, true);
  } catch (const std::exception& e) {
    LOG("Failed to put {} to file cache: exception: {}", path, e.what());
    return false;
  }
  LOG("Succeeded to put {} to file cache", path);
  return true;
}

bool
FileBackend::get(const std::string& url, const std::string& path)
{
  try {
    Util::copy_file(url, path, false);
  } catch (const std::exception& e) {
    LOG(
      "Failed to get {} from file cache: exception: {}", path, e.what());
    return false;
  }
  LOG("Succeeded to get {} from file cache", path);
  return true;
}

It will look in the local directory first and in the remote directory second, though.

@jrosdahl

jrosdahl commented Jun 27, 2021 •

Copy link
Copy Markdown
Member

I consider this done as of f8789e2 so I'll close this one.

It's currently not possible to configure ccache to query a secondary storage before the primary storage, but that can be done in the future.

@jrosdahl jrosdahl closed this Jun 27, 2021
@jrosdahl jrosdahl added the status: won't fix Will not fix/implement/merge label Jun 27, 2021
@jrosdahl jrosdahl mentioned this pull request Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

issue: feature New feature status: won't fix Will not fix/implement/merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants