UITableView cell cache that cures scroll-lags on cell instantiating

Overview

Build Status Pod Version codebeat badge Carthage compatible

UITableView + Cache

https://github.com/Kilograpp/UITableView-Cache

UITableView cell cache that cures scroll-lags on a cell instantiating.

Introduction

UITableView+Cache is a light UITableView category that purges scroll-lag that occurs on a new cell instantiation during scroll. It makes UITableView instantiate and cache cells before cellForRow:atIndexPath: call. It also provides simple interface very similar to existing registerClass/registerNib one.

Installation

CocoaPods

	pod 'UITableView+Cache'

Carthage

	github "Kilograpp/UITableView-Cache" "master"

Manual importing

Just add all files from src directory to your project.

Usage

When registering custom cells, call overriden registerClass/registerNib method instead of a default. UITableView+Cache swizzles dequeueReusableCellWithIdentifier methods with a private one that uses its own cache and implements registerClass/registerNib mechanism on itself. When dequeueReusableCellWithIdentifier is called and returns nil - the cache is asked for a cell. If cache is empty then cell is created using registered class or nib.

Swift 3

import UITableView_Cache

...

override func viewDidLoad() {
	super.viewDidLoad()

	self.tableView.registerClass(TableViewCodeCell.self, forCellReuseIdentifier: "MyReuseIdentifier", cacheSize: 10)
	self.tableView.registerNib(TableViewCodeCell.nib, forCellReuseIdentifier: "MyReuseIdentifier", cacheSize: 10)
}

...

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
	let cell = self.tableView.dequeueReusableCellWithIdentifier("MyReuseIdentifier") as! TableViewCodeCell
	return cell
}

Objective-C

- (void)viewDidLoad {
	[super viewDidLoad];

	[self.tableView registerClass:[TableViewCodeCell class] forCellReuseIdentifier:@"MyReuseIdentifier" cacheSize:10];
	[self.tableView registerNib:[TableViewNibCell nib] forCellReuseIdentifier:@"MyNibReuseIdentifier" cacheSize:10];
}

...

- (MyCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	MyCell* cell = [tableView dequeueReusableCellWithIdentifier:@"MyReuseIdentifier"];
	return cell;
}

Make sure to call dequeueReusableCellWithIdentifier:reuseIdentifier method and NOT dequeueReusableCellWithIdentifier:reuseIdentifier:forIndexPath: one. They perform different logic and a crash will occure on wrong method use.

Storyboards

Storyboards are not supported, cached cells should be registered from code. Nevertheless, if you strongly require storyboard usage then you could swizzle basic UITableView's registerNib/registerClass methods for your own and call. But I won't recommend this solution for it tampers UITableView mechanism.

Best Practises

As you know any cache consumes some memory. Best advice I could give is to keep track of your tableViews and free them as soon as possible. Having too many tableViews may cause memory pressure on your app.

License

UITableView+Cache is available under the MIT license. See the LICENSE file for more info.

Author

Mehdzor

You might also like...
Fast, non-deadlocking parallel object cache for iOS, tvOS and OS X

PINCache Fast, non-deadlocking parallel object cache for iOS and OS X. PINCache is a fork of TMCache re-architected to fix issues with deadlocking cau

๐Ÿ’พ Simple memory & disk cache

Cache ๐Ÿ’พ Simple memory & disk cache Usage ๐Ÿง‘โ€๐Ÿ’ป Default let cache = CacheString() try memory.save("MyValue", forKey: "MyKey") let cached = try cac

Cache library for videos for React Native

@lowkey/react-native-cache Cache everything Installation npm install @lowkey/react-native-cache Usage import ReactNativeCache from "@lowkey/react-nati

CachedAsyncImage is the simplest way to add cache to your AsyncImage.

CachedAsyncImage ๐Ÿ—ƒ๏ธ CachedAsyncImage is AsyncImage, but with cache capabilities. Usage CachedAsyncImage has the exact same API and behavior as AsyncI

๐Ÿˆ Cache CocoaPods for faster rebuild and indexing Xcode project.
๐Ÿˆ Cache CocoaPods for faster rebuild and indexing Xcode project.

Motivation Working on a project with a huge amount of pods I had some troubles: - Slow and unnecessary indexing of pods targets, which implementation

XCRemoteCache is a remote cache tool for Xcode projects.
XCRemoteCache is a remote cache tool for Xcode projects.

XCRemoteCache is a remote cache tool for Xcode projects. It reuses target artifacts generated on a remote machine, served from a simple REST server. H

A simple cache that can hold anything, including Swift items

CacheIsKing CacheIsKing is a simple cache that allows you to store any item, including objects, pure Swift structs, enums (with associated values), et

A simple but flexible cache

Carlos A simple but flexible cache, written in Swift for iOS 13+ and WatchOS 6 apps. Breaking Changes Carlos 1.0.0 has been migrated from PiedPiper de

MrCode is a simple GitHub iPhone App that can cache Markdown content (include images in HTML) for read it later.
MrCode is a simple GitHub iPhone App that can cache Markdown content (include images in HTML) for read it later.

MrCode is a simple GitHub iPhone App that can cache Markdown content (include images in HTML) for read it later.

Owner
null
Cache - Nothing but Cache.

Cache doesn't claim to be unique in this area, but it's not another monster library that gives you a god's power. It does nothing but caching, but it does it well. It offers a good public API with out-of-box implementations and great customization possibilities. Cache utilizes Codable in Swift 4 to perform serialization.

HyperRedink 2.7k Dec 28, 2022
Apple Asset Cache (Content Cache) Tools

AssetCacheTool A library and tool for interacting with both the local and remote asset caches. This is based on research I did a few years ago on the

Kenneth Endfinger 21 Jan 5, 2023
CachyKit - A Caching Library is written in Swift that can cache JSON, Image, Zip or AnyObject with expiry date/TTYL and force refresh.

Nice threadsafe expirable cache management that can cache any object. Supports fetching from server, single object expire date, UIImageView loading etc.

Sadman Samee 122 Dec 28, 2022
Cachyr A typesafe key-value data cache for iOS, macOS, tvOS and watchOS written in Swift.

Cachyr A typesafe key-value data cache for iOS, macOS, tvOS and watchOS written in Swift. There already exists plenty of cache solutions, so why creat

Norsk rikskringkasting (NRK) 124 Nov 24, 2022
Carlos - A simple but flexible cache, written in Swift for iOS 13+ and WatchOS 6 apps.

Carlos A simple but flexible cache, written in Swift for iOS 13+ and WatchOS 6 apps. Breaking Changes Carlos 1.0.0 has been migrated from PiedPiper de

National Media & Tech 628 Dec 3, 2022
MemoryCache - type-safe, thread-safe memory cache class in Swift

MemoryCache is a memory cache class in swift. The MemoryCache class incorporates LRU policies, which ensure that a cache doesnโ€™t

Yusuke Morishita 74 Nov 24, 2022
A lightweight generic cache for iOS written in Swift with extra love for images.

Haneke is a lightweight generic cache for iOS and tvOS written in Swift 4. It's designed to be super-simple to use. Here's how you would initalize a J

Haneke 5.2k Dec 29, 2022
High performance cache framework for iOS.

YYCache High performance cache framework for iOS. (It's a component of YYKit) Performance You may download and compile the latest version of sqlite an

null 2.3k Dec 16, 2022
Everyone tries to implement a cache at some point in their iOS appโ€™s lifecycle, and this is ours.

Everyone tries to implement a cache at some point in their appโ€™s lifecycle, and this is ours. This is a library that allows people to cache NSData wit

Spotify 1.2k Dec 28, 2022
Track is a thread safe cache write by Swift. Composed of DiskCache and MemoryCache which support LRU.

Track is a thread safe cache write by Swift. Composed of DiskCache and MemoryCache which support LRU. Features Thread safe: Implement by dispatch_sema

Cheer 268 Nov 21, 2022