lib/shared.js
function checkForAndDeleteMaxCacheVersions(options, serverless) {
  // If we're using the static cache, and we have static cache max versions enabled
  if (
    options.useStaticCache &&
    options.staticCacheMaxVersions &&
    parseInt(options.staticCacheMaxVersions) > 0
  ) {
    // Get the list of our cache files
    const files = glob.sync(
      [path.join(getUserCachePath(options), '*_slspyc/')],
      { mark: true }
    );
    // Check if we have too many
    if (files.length >= options.staticCacheMaxVersions) {
      // Sort by modified time
      files.sort(function(a, b) {
        return (
          fse.statSync(a).mtime.getTime() - fse.statSync(b).mtime.getTime()
        );
      });
      // Remove the older files...
      var items = 0;
      for (
        var i = 0;
        i < files.length - options.staticCacheMaxVersions + 1;
        i++
      ) {
        rimraf.sync(files[i]);
        items++;
      }
      // Log the number of cache files flushed
      serverless.cli.log(
        `Removed ${items} items from cache because of staticCacheMaxVersions`
      );
    }
  }
}
function checkForAndDeleteMaxCacheVersions(options, serverless) {
  // If we're using the static cache, and we have static cache max versions enabled
  if (
    options.useStaticCache &&
    options.staticCacheMaxVersions &&
    parseInt(options.staticCacheMaxVersions) > 0
  ) {
    // Get the list of our cache files
    const files = glob.sync(
      [path.join(getUserCachePath(options), '*_slspyc/')],
      { mark: true }
    );
    // Check if we have too many
    if (files.length >= options.staticCacheMaxVersions) {
      // Sort by modified time
      files.sort(function(a, b) {
        return (
          fse.statSync(a).mtime.getTime() - fse.statSync(b).mtime.getTime()
        );
      });
      // Remove the older files...
      var items = 0;
      for (
        var i = 0;
        i < files.length - options.staticCacheMaxVersions + 1;
        i++
      ) {
        rimraf.sync(files[i]);
        items++;
      }
      // Log the number of cache files flushed
      serverless.cli.log(
        `Removed ${items} items from cache because of staticCacheMaxVersions`
      );
    }
  }
}
function checkForAndDeleteMaxCacheVersions ( options , serverless ) { // If we're using the static cache, and we have static cache max versions enabled if ( options . useStaticCache && options . staticCacheMaxVersions && parseInt ( options . staticCacheMaxVersions ) > 0 ) { // Get the list of our cache files const files = glob . sync ( [ path . join ( getUserCachePath ( options ) , '*_slspyc/' ) ] , { mark : true } ) ; // Check if we have too many if ( files . length >= options . staticCacheMaxVersions ) { // Sort by modified time files . sort ( function ( a , b ) { return ( fse . statSync ( a ) . mtime . getTime ( ) - fse . statSync ( b ) . mtime . getTime ( ) ) ; } ) ; // Remove the older files... var items = 0 ; for ( var i = 0 ; i < files . length - options . staticCacheMaxVersions + 1 ; i ++ ) { rimraf . sync ( files [ i ] ) ; items ++ ; } // Log the number of cache files flushed serverless . cli . log ( ` ${ items } ` ) ; } } }
This helper will check if we're using static cache and have max
versions enabled and will delete older versions in a fifo fashion
@param  {Object} options
@param  {Object} serverless
@return {undefined}
This helper will check if we re using static cache and have max versions enabled and will delete older versions in a fifo fashion