Skip to content
Advertisement

How to cache BLOB type in Laravel

Hi everyone,

Is there a way to cache BLOB types temporarily in Laravel ?

Scenario:
I’m gonna cache some data MEDIUMBLOB with the size of 2048KB temporarily. These data are actually parts of a large single file 16MB. After caching all parts, they will be combined together into a single file, then will be removed from cache.

The content of each single part is given by file_get_contents function.

I’m already doing this with MySQL. (However, there are lots of queries and takes time to be done.)

Is there a better way to store MEDIUMBLOB data temporarily in Cache storage ?

I’ve faced with Redis and Cache in Laravel, but I’m not sure they support MEDIUMBLOB.

Advertisement

Answer

Here’s the main point. In the end a BLOB is just a string of bytes. The major difference with a formal string type is that a BLOB doesn’t have any sort of encoding or collation associated with it. It’s a kind of binary string which is another way of saying “generic data”. file_get_contents also generally returns this sort of “generic data”.

Laravel’s cache is build to be generic like that so it doesn’t have any specific data type associated with it. It’s just a store of key/value pairs and the keys must be ascii strings while the values can be anything Laravel serialises things before they go in the cache so basically anything that can be represented as a variable in PHP and is serializable can be cached.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement