The lan-cache utility is automatically deployed with all Addigy agents and helps distribute files and packages across the local area network (LAN).

This helps reduce the amount of internet bandwidth used when downloading software to devices on the same LAN.


When a lan-cache device needs to download a file to complete a command from Addigy, the first thing it will do is determine which peer to use. Lan cache devices each have a weighting set and the agent will check with the highest-weighted device on the network to see if it has the needed file. 


If the highest-weighted device does not have the file it needs, it will check other lan-cache devices (aka peers) on the same local subnet to see if it can find the file. If the file is not available within the subnet, it will download it from the source (e.g. download the file over the internet).


Once device has downloaded a file with lan-cache, that file is added to the lan-cache index so other devices will know it is available to download from that device. So, if a device already recently downloaded a file and it's still has a copy  that device), when the device checks the lan-cache index, it will see that it already has it and just use it's own copy.


Using lan-cache

The following command will display the parameters available for managing the Addigy lan-cache utility.

/Library/Addigy/lan-cache ?


Output:

  -md5 string
      Tells the cache client to check the check the downloaded file's md5 hash againt the md5 hash provided. If it fails, the file will be rejected.
      This option only works with the download action.
  -peer-proxy
      Sets the device to act as a proxy for his peers. Values should be either true or false. 
      Enabling this setting will mean that this device will always serve the files requested even if it is not currently in its cache.
      In case where the file is not in its cache, the file will be fetched from the public web resource, cached locally, and served to its peer.
  -set-default-settings
      Resets the lan-cache settings to its default values.
  -set-peer-proxy-setting
      Indicates that you are trying enable or disable the peer-proxy setting. The value from the peer-proxy option will be used.
  -set-weight-setting
      Indicates that you are trying set the weight setting. The value from the weight option will be used.
  -v  Prints the current version.
  -weight int
      Sets the peer weight for this device. The weight can be any integer.
      The weight influences the likelihood of a device to get polled by other devices in the network.
      Peers will be checked in decreasing weight order. This means that a device with a weight of 2 will be polled for files before a device with a weight of 1.
      Devices have a weight of 1 by default.
Actions:
  download web_url local_path
    Downloads the file specified by web_url to the local_path.
  peers
    Outputs a json formatted list of the current peers from the device.
  host
    Starts the lan-cache server.


Advanced lan-cache Command Examples

To prioritize a device as a lan-cache host, use this command to set the weight of a device device to 100.

/Library/Addigy/lan-cache -set-weight-setting -weight=100


After changing the weight, relaunch the lan-cache server to have it pick up the new weight setting.

sudo launchctl unload /Library/LaunchDaemons/com.addigy.lan-cache.plist && sudo launchctl load /Library/LaunchDaemons/com.addigy.lan-cache.plist


To see what peers are visible to a device on the subnet using lan-cache, run this command.

/Library/Addigy/lan-cache peers


To set a device as a download proxy server, run this command. "Proxy" devices will download on behalf of other devices and then serve them the file using lan-cache.

/Library/Addigy/lan-cache -peer-proxy -set-peer-proxy-setting


Best Practices

Ideally, customizing the lan-cache settings in your network will include both a peer proxy and weight setting to designate a specific machine as a caching server.

This implies that all files will be downloaded from a specific server before distributed to other devices within the environment.


If only the 'weight' setting is implemented, devices will attempt to fetch from the higher weighted peer before checking other peers and/or downloading from the internet.


Choosing the right method of lan-caching is really dependent on your network configuration(s), and what is ideal for your environment.


Additional Notes

  • Logs are stored in /Library/Addigy/logs/cache.log.
  • Downloaded files from lan-cache are stored in /Library/Addigy/download-cache/downloaded (We have a Community Script called 'Purge Addigy Cache' available)
  • lan-cache runs on port 64084 on all devices (https://localhost:64084)
  • lan-cache uses DNS Service Discovery (aka mDNS or Bonjour) to identify peers
  • To use lan-cache to download files, see our article Creating Custom Software with Large Files
  • lan-cache uses an SSL certificate for certificate pinning when downloading and validating files
  • lan-cache uses a MD5 hash algorithm to validate software before distribution