       (try
         (delete-deleted-domains domains-info global-config local-config)
         (sync-data-updated domains-info global-config local-config)
+        (cleanup-domains fs domains-info global-config local-config)
         (log-message "Caching global config " cache-config)
         (cache-global-config! local-config cache-config)
         (log-message "Cached config " (read-cached-global-config local-config))

                        (fn [domain]
                          (use-cache-or-update domain domains-info global-config local-config))))


(defn sync-updated [global-config local-config token]
  "Only fetch domains from remote if a newer version is available.

        remote-vs (DomainStore. fs remote-path)
        local-vs (DomainStore. lfs local-domain-root (.getSpec remote-vs))]
    (if (domain-needs-update? local-vs remote-vs)
      (load-domain fs
                   local-config
                   local-domain-root
                   remote-path
                   (domain/host-shards (domains-info domain)))
      ;; use cached domain from local-dir (no update needed)
      (open-domain local-config
                   (str (path local-dir domain))
                   (domain/host-shards (domains-info domain))))))

(defn delete-deleted-domains [domains-info global-config local-config]
  "Deletes all domains from local filesystem that have been deleted from the global config."
