How to cache an array?

Can i save array in cache?
and what is the key i have to add?
if i am saving data in cache than how can i get that data from cache?

Magento 2 can only cache the strings, so the varables of the other types should be convert to string before caching.
Learn about the PHP serialize function.
If you are caching an array, which does not contain an object in its values, then json_encode will be a faster alternative to serialize.

A post was split to a new topic: How to cache custom data programmatically?