Download the PHP package freshvine/expiringmediacache without Composer

On this page you can find all versions of the php package freshvine/expiringmediacache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package expiringmediacache

Expiring Media Cache in PHP

Build Status Total Downloads Version License

A simple way to cache media locally and remove it once it has expired.

The core concept of this library is simple. It creates local to you copies of accessible remote media. At the same time it creates and maintains an index of all the cached media. After a pre-determined period of time the local copies of media will expire, and be removed from your file system, and the index.

This is ideal for projects where you want to include temporary content from third party sources, but do not want to build up a large repository of old and irrelevant content you won't use in the future.

Since PHP is a single threaded (and thus a blocking language) you will likely want to process these media requests separately from your primary page load (via an XHR request on DOM Ready for example). This will greatly improve your load performance. However you can choose to implement this library in any way you see fit.

Features

Adding to your Project

Install the composer package:

The library will use a default directory and path for the cache unless you define a different one. The default directory is within the same directory as the library in a folder called /media-cache/. The library will also attempt to define the public URL to access this directory. It will only be successful in simple and direct server configurations (no advanced apache/ngnix mapping setups).

Example Usage

The constructor allows you to define the local path, and the local public URL when created. Below being an example.

Function Reference

cacheThis

This is the primary caching function. It takes a remote URL that you would like to cache as it's primary attribute. You can add an optional Prefix and/or Suffix to the filename. This is simply for your sanity when looking into the directory storing the media.

Returns a CacheModel object

$ExpiringMedia->cacheThis( String $RemoteURL, String $FilenamePrefix = NULL, String $FilenameSuffix = NULL );

getURL

You are going to want the URL from the cache. This is the function that gets that for you. To keep the cache file more manageable the URL is not stored directly in the cache, but it is generated by the ExpiringMediaCache class when requested.

Returns a URL as a string

$ExpiringMedia->getURL( CacheModel &$CacheModel );
$PublicURL = $ExpiringMedia->getURL( $ExpiringMedia->cacheThis() );

cleanUp

This function executes three clean up steps. It will remove any expired media from the cache, it will remove any cache entries whose related file no longer exists on the file system, and it will remove excess files from the directory in the file system. You can choose to execute this on every destructor with $ExpiringMedia->setCleanupOnDestruct( true );.

Returns boolean

$ExpiringMedia->cleanUp();

find

This accepts a remote URL and returns the cache model if it exists.

Returns a CacheModel object

$ExpiringMedia->find( String $RemoteURL );

reloadCache

If you need to unload the state of the cache and load the cache from the JSON file again you call this function. This function is called when you change the LocalPath via setLocalPath().

Returns boolean

$ExpiringMedia->reloadCache();

writeCache

Calling this function allows you to force a writing of the cache to the _media-cache.json file. Even calling this function explicitly will only write the cache if there has been a change made to the cache.

Returns boolean

$ExpiringMedia->writeCache();

Configuration Options

CacheMethod

The method of caching defines how to apply the lifetime to a cached item. When set to 'first' the lifetime will be measured from when the item was first cached. When set to 'request' it will be measured against when it was last requested from the cache (not from the filesystem). Note that this is stored with each cached item.

Options: first, request
Default: first

    $ExpiringMedia->setCacheMethod( $cacheMethod );
    $ExpiringMedia->getCacheMethod( );

CleanupOnDestruct

If you are not caching many files you can opt to cleanup the cache everytime the class is loaded. This can be expensive as it requires the processing of every cached entry. By default this is disabled and you need to manually call $ExpiringMedia->cleanUp(); to remove entries that have expired, or whose media were otherwise removed.

Options: Boolean Default: false

$ExpiringMedia->setCleanupOnDestruct( true );
$ExpiringMedia->getCleanupOnDestruct();

Lifetime

The lifetime is the period of time in minutes that an item should remain in the cache.

Default: 10080 Minutes (7 Days)

$ExpiringMedia->setLifetime( 7 * 24 * 60 );
$ExpiringMedia->getLifetime();

LocalPath

This allows you to define the location that the cache should exist. This directory must only be used for the media cache, as the cache will remove any unexpected files from the directory. When you define this path using the supplied local file system controller it will attempt to determine the public URL as well.

Default: __DIR__ . '/media-cache/'

$ExpiringMedia->setLocalPath( __DIR__ . '/media-cache/' );
$ExpiringMedia->setLocalPath( );

LocalPublicURL

Related to the LocalMediaPath - this is the public URL to the supplied media path.

Default: YOURDOMAIN/vendor/freshvine/expiring-media-cache/media-cache/

$ExpiringMedia->setLocalPublicURL( 'http://localhost:8080/media-cache/' );
$ExpiringMedia->getLocalPublicURL( );

WriteEveryChange

Every time the ExpiringMediaCache is unset the cache writing is triggered. If you want to write the cache whenever a change is made you can do so my enabling this. Note that if you are storying a lot of media this will have some level of performance penalty.

Default: false

$ExpiringMedia->setWriteEveryChange( true );
$ExpiringMedia->getWriteEveryChange( );

UserAgent

To make requests for media you need to supply a user agent string. This should be updated from time to time to ensure it looks modern. Services may block certain UA strings over time.

Default: false

$ExpiringMedia->setUserAgent( 'User Agent Browser String' );
$ExpiringMedia->getUserAgent( );

FileController

This library includes a file controller written for the local filesystem that PHP is installed on. You may need to extend the abstracted functions in the File controller to support a different storage location (like a CDN or other). You can use the Controllers\FileLocal.php to help you.

Default: FreshVine\ExpiringMediaCache\Controllers\FileLocal

$MyFileController = new FreshVine\ExpiringMediaCache\Controllers\FileLocal( $ExpiringMedia );
$ExpiringMedia->setFileController( $MyFileController );

All versions of expiringmediacache with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package freshvine/expiringmediacache contains the following files

Loading the files please wait ....