Synchronize the current packages.json and in-memory cache with the remote
repository. If filter(pkg) is given, it should return the object to store in
the synchronized file. Otherwise the entire record will be stored.