ল্যান ক্যাশ
এই অধ্যায়টি এখনও অনুবাদ হয়নি, তাই ইংরেজিতে দেখানো হচ্ছে।
এই পাতায়
LAN Cache keeps a copy of every media file people watch - videos, thumbnails, avatars, subtitles - in a folder close by: on this server, or on a share on your own network. When the place the files really live stops answering, the site carries on playing from that copy instead of showing broken videos.
Who it is for
It helps a site whose media is not on this server:
- the files live on a file server (Admin → Media & FFmpeg → File server (FTP), see Conversion);
- the files are still on an older site (Admin → Settings → Media → Media origin, for example after a move from PlayTube);
- or the files sit on another machine on your network.
When every file is on this server already, the plugin has nothing to do.
Switching it on
LAN Cache is a free plugin and works with every licence. Switch it on at Admin → Plugins. It needs no tables. It sets the cache folder to cache/media inside the site, the size limit to 20 GB and the health check to every 60 seconds.
The admin menu then shows a LAN Cache group under Plugins with two pages: LAN Cache (admin/plugin.php?code=lan-cache) and Cached files.
How it decides
| The situation | What happens |
|---|---|
| The file is on this server | Served from here. The cache is not involved. |
| The file is in the cache | Served from the cache (only while the far end is down, if you switch Serve from the cache whenever a copy exists off). |
| Only the far end has it | The visitor gets it from there, and a copy is put aside for next time. |
| The far end is down, a copy exists | Served from the cache. The visitor notices nothing. |
| The far end is down, no copy | A thumbnail shows an offline placeholder; a video says the file server is away. The rest of the page works. |
Whether the far end is up is checked in the background and remembered, so a page view never waits for the network.
The settings
The four figures at the top say whether the far end is Up or Down, how many Files cached, the Cache size, and whether the files go out Direct (the web server sends them) or through PHP.
Where the copies live
- Cache folder - any folder PHP can read and write: the default
cache/media, a mounted share such as/mnt/media, or a network path. Keep it outsideuploads/. Inside the site's own folder, the web server hands the copies out itself, which is the fastest; anywhere elseplugins/lan-cache/serve.phpstreams them with signed links. - Largest the cache may get (MB) - 0 means no limit. When it is full, the files nobody has watched for longest go first.
- Check the far end every (seconds).
- Folders to cache - comma separated. Empty follows the Folders to handle of the Media origin setting, else
uploads/,upload/. - Copy a file the first time it is watched - the visitor still gets the original; the copy is made in the background.
- Serve from the cache whenever a copy exists - on: a cached copy is always the one played, fastest for viewers and lightest on the far end. Off: the cache is used only while the far end is down.
Where the originals come from
- Origin address (HTTP) - leave it empty to follow the file server's web address or the Media origin address.
- Copy from an FTP server - the plugin's own FTP sign-in, separate from the site's file server settings: FTP host, Port, Username, Password, Folder on the server the media lives under, Passive mode (usually right) and FTPS (explicit TLS). It needs PHP's FTP extension; the page warns when it is missing.
When both are filled in, FTP is tried first.
Speed
- How cached files are sent when the folder is outside the web root - Automatic (X-Sendfile when Apache offers it, else PHP), PHP streams (works everywhere), Always X-Sendfile (Apache mod_xsendfile or LiteSpeed) or X-Accel-Redirect (nginx). With the folder inside the site none of this matters.
- nginx internal location - for X-Accel-Redirect only; the page prints the
locationblock to add. - Seconds one warm run may take - default 50, so a copying run never holds a cron slot open.
Press Save.
Filling and emptying it
- Copy the next 5 and Copy the next 25 copy files now: first those waiting in line, otherwise the newest videos and their thumbnails.
- Check the far end now asks at once instead of waiting.
- Test the FTP sign-in appears once FTP is set up.
- Empty the cache removes every copy; they are fetched again as people watch.
Next in line lists the files waiting to be copied.
The cache also fills itself. The plugin adds a LAN cache job to Admin → Cron jobs that runs every ten minutes as part of the site's one cron line and copies up to 25 files (see Scheduled jobs). The page also shows a separate warm.php cron line; you do not need it when the site's own cron line runs.
The Cached files page
Every copy, 50 to a page, with Look for (part of a path or name) and Order (Newest copies first, Least watched first, Largest first). Each row shows the kind (video, image, audio, subtitles), the size, when it was copied and last watched, and two links: on the site (the address the player uses) and the copy. Delete removes one copy; tick several for Remove from the cache. Removing a copy never touches the original.
Good to know
- A copy is written under a temporary name and renamed when complete, so a half-copied file is never served.
- When the site deletes a video, its copies leave the cache too.
- The cache folder gets its own
.htaccess: nothing in it can run as a script and the folder cannot be listed. - What
serve.phpsends is counted by the Bandwidth Monitor.
Honest limits
- A file that was never copied cannot play while the far end is down. Let the cron job run for a while, or press Copy the next 25 a few times, before you rely on it.
- Over HTTP, any answer from the far end counts as "up" - even an error page - so a server that answers but has lost its files is not detected.
- The cache needs the disk space you give it. A video site's files are large; set Largest the cache may get to what the disk can spare.