https://github.com/sdwebimage/sdwebimagepinplugin
A SDWebImage plugin to integrate PINCache for custom image caching
https://github.com/sdwebimage/sdwebimagepinplugin
carthage cocoapods ios macos pincache sdwebimage tvos watchos
Last synced: 6 months ago
JSON representation
A SDWebImage plugin to integrate PINCache for custom image caching
- Host: GitHub
- URL: https://github.com/sdwebimage/sdwebimagepinplugin
- Owner: SDWebImage
- License: mit
- Created: 2020-04-12T08:01:54.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-19T08:14:37.000Z (almost 5 years ago)
- Last Synced: 2025-06-04T02:43:11.420Z (7 months ago)
- Topics: carthage, cocoapods, ios, macos, pincache, sdwebimage, tvos, watchos
- Language: Objective-C
- Size: 68.4 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SDWebImagePINPlugin
[](https://travis-ci.org/SDWebImage/SDWebImagePINPlugin)
[](https://cocoapods.org/pods/SDWebImagePINPlugin)
[](https://cocoapods.org/pods/SDWebImagePINPlugin)
[](https://cocoapods.org/pods/SDWebImagePINPlugin)
[](https://github.com/SDWebImage/SDWebImagePINPlugin)
[](https://swift.org/package-manager/)
[](https://codecov.io/gh/SDWebImage/SDWebImagePINPlugin)
## What's for
SDWebImagePINPlugin is a plugin for [SDWebImage](https://github.com/rs/SDWebImage/) framework, which provide the image loading support for [PINCache](https://github.com/pinterest/PINCache) cache system.
You use `PINCache` instead of `SDImageCache` for image cache system, which may better memory cache performance (By taking advanced of LRU algorithm), and disk cache performance (By taking advanced of queue management and age/bytes LRU algorithm)
## Usage
#### PINCache
To enable `PINCache` instead of `SDImageCache`, you can bind the cache for shared manager, or create a custom manager instead.
+ Objective-C
```objectivec
// Use `PINCache` for shared manager
SDWebImageManger.defaultImageCache = [PINCache cacheWithName:@"name"];
```
+ Swift
```swift
// Use `PINCache` for shared manager
SDWebImageManger.defaultImageCache = PINCache(name: "name")
```
You can also attach the custom cache for individual image requests via `.imageCache` context option.
+ Objective-C
```objectivec
// Use `PINCache` for single URL request
[imageView sd_setImageWithURL:url placeholderImage:nil options:0 context:@{SDWebImageContextImageCache: @(pinCache)} progress:nil completion:completion];
```
+ Swift
```swift
// Use `PINCache` for single URL request
imageView.sd_setImage(with: url, placeholderImage: nil, context: [.imageCache : pinCache], progress: nil, completion: completion);
```
### PINDiskCache && PINMemoryCache
You can also use `PINMemoryCache` or `PINDiskcache` to customize memory cache / disk cache only. See [Custom Cache](https://github.com/rs/SDWebImage/wiki/Advanced-Usage#custom-cache-50) wiki in SDWebImage.
+ Objective-C
```objectivec
// Use `PINMemoryCache` for shared `SDImageCache` memory cache implementation
SDImageCacheConfig.defaultCacheConfig.memoryCacheClass = PINMemoryCache.class;
// Use `PINDiskcache` for shared `SDImageCache` disk cache implementation
SDImageCacheConfig.defaultCacheConfig.diskCacheClass = PINDiskcache.class;
```
+ Swift
```swift
// Use `PINMemoryCache` for `SDImageCache` memory cache implementation
SDImageCacheConfig.default.memoryCacheClass = PINMemoryCache.self
// Use `PINDiskcache` for `SDImageCache` disk cache implementation
SDImageCacheConfig.default.diskCacheClass = PINDiskcache.self
```
## Requirements
+ iOS 9+
+ tvOS 9+
+ macOS 10.11+
+ watchOS 2.0+
+ Xcode 11+
## Installation
#### CocoaPods
SDWebImagePINPlugin is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:
```ruby
pod 'SDWebImagePINPlugin'
```
#### Carthage
SDWebImagePINPlugin is available through [Carthage](https://github.com/Carthage/Carthage).
```
github "SDWebImage/SDWebImagePINPlugin"
```
#### Swift Package Manager (Xcode 11+)
SDWebImagePINPlugin is available through [Swift Package Manager](https://swift.org/package-manager).
```swift
let package = Package(
dependencies: [
.package(url: "https://github.com/SDWebImage/SDWebImagePINPlugin.git", from: "0.3.0")
]
)
```
## Author
DreamPiggy, lizhuoli1126@126.com
## License
SDWebImagePINPlugin is available under the MIT license. See the LICENSE file for more info.