Sitelet https://github.com/purescript/psc-package/issues/152
Skip to content

Use a global package cache #152

Description

@Pauan

I'm not sure whether this belongs in this repository or purescript/purescript

Right now, psc-package downloads packages and places them into the .psc-package folder:

.psc-package
└─┬ psc-0.10.2
  └─┬ prelude
    └─┬ v2.1.0
      └── ...

Instead, I propose for it to install packages into a single cache folder, and then create a symlink in .psc-package:

.psc-package
└── psc-0.10.2 -> $XDG_CACHE_HOME/psc-package/package-sets/psc-0.10.2
$XDG_CACHE_HOME
└─┬ psc-package
  ├─┬ packages
  │ └─┬ prelude
  │   └─┬ v2.1.0
  │     └── ...
  └─┬ package-sets
    └─┬ psc-0.10.2
      └── prelude -> $XDG_CACHE_HOME/psc-package/packages/prelude/v2.1.0

Notice that there are actually two symlinks:

  • .psc-package/psc-0.10.2 symlinks to $XDG_CACHE_HOME/psc-package/package-sets/psc-0.10.2

    The reason is: if multiple PureScript programs use the same package set, it only needs to be downloaded once.

  • $XDG_CACHE_HOME/psc-package/package-sets/psc-0.10.2/prelude symlinks to $XDG_CACHE_HOME/psc-package/packages/prelude/v2.1.0

    The reason is: if the same package+version is included in multiple package sets, it only needs to be downloaded once.

This has a few benefits:

  • It saves a non-trivial amount of internet bandwidth.

  • It saves time, since the files do not need to be downloaded/unzipped/untarred/copied repeatedly.

  • It saves disk space, since only a single copy of a package or package set needs to exist (per version).

  • It avoids unnecessary file writing, which is important on SSDs.

P.S. It's probably a good idea to make everything inside of $XDG_CACHE_HOME/psc-package read-only. If it is read-write, and if somebody modifies their local .psc-package folder, then it will affect all PureScript programs on their computer (because of the symlinks). This is very unexpected behavior.

P.P.S. This proposal uses the $XDG_CACHE_HOME env var, which defaults to $HOME/.cache/. That is the correct location to use on *nix. Windows should probably use %LOCALAPPDATA% and Mac should probably use ~/Library/Caches/

You might find this useful, though it does not seem to support Mac.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions