Skip to content

Muhammad-Darain/Instagram

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸŽ₯ CacheManager

Instagram.mp4

Description

VideoCacheManager is a lightweight Swift utility for caching videos locally in an iOS application. It helps efficiently store and retrieve downloaded video files, reducing redundant network requests and improving performance.

πŸš€ Features

  • βœ… Singleton instance for easy access
  • βœ… Stores cached videos in the app's cache directory
  • βœ… Retrieves cached videos using a unique key
  • βœ… Downloads and caches videos asynchronously
  • βœ… Handles errors gracefully

πŸ“Œ Usage

πŸ” Retrieve Cached Video

if let cachedURL = VideoCacheManager.shared.getCachedVideoURL(for: "videoKey") {
    // Use the cached video
}
let videoURL = URL(string: "https://example.com/video.mp4")!
VideoCacheManager.shared.cacheVideo(from: videoURL, key: "videoKey") { cachedURL in
    if let cachedURL = cachedURL {
        print("Video cached at:", cachedURL)
    } else {
        print("Failed to cache video")
    }
}

βš™οΈ How It Works

  • Uses FileManager to create a VideoCache directory inside the app’s cache folder.
  • Checks if a video is already cached before downloading.
  • Downloads the video asynchronously using URLSession.downloadTask.
  • Moves the downloaded file to the cache directory for persistent storage.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages