Skip to content

Cache fails to store large files #85

@vilinskiy-playdayteam

Description

@vilinskiy-playdayteam

Whenever we try to save large files (>100MB, actual size depends on device capabilities) to cache, nothing happens except console log message like

*** mach_vm_map(size=997462016) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

The problem is in SPTPersistentCache method

- (NSError *)storeDataSync:(NSData *)data
                    forKey:(NSString *)key
                       ttl:(NSUInteger)ttl
                    locked:(BOOL)isLocked
              withCallback:(SPTPersistentCacheResponseCallback)callback
                   onQueue:(dispatch_queue_t)queue

The following code does not work for large rawDataLength
NSMutableData *rawData = [NSMutableData dataWithCapacity:rawDataLength];

One way to handle large amounts of data is to fill temporary file with relatively small blocks of data first and then writing it atomically to target filePath

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions