A method for writing metadata into a cache, wherein a flash storage is used as the cache, wherein a storage area of the flash storage of the cache comprises multiple chunks, one chunk comprises one chunk metadata area and one chunk data area, the chunk metadata area comprises at least one metadata block, the chunk data area comprises at least one data area corresponding to the at least one metadata block, the metadata block comprises multiple pieces of metadata, the data area comprises multiple data blocks, the metadata block is in a one-to-one correspondence with the data area, the metadata is in a one-to-one correspondence with the data block, and the method comprises: receiving an IO request write command, wherein the IO request write command comprises metadata of to-be-written data; obtaining a buddy group that is currently being processed from a global buddy queue, and using the buddy group as a first buddy group, wherein each buddy group comprises multiple cache blocks in a memory, each buddy group belongs to one metadata group, and one metadata group is corresponding to one metadata block; determining whether the first buddy group has a remaining cache block and whether all metadata of the to-be-written data can be written into the remaining cache block; and when the first buddy group has the remaining cache block and all the metadata of the to-be-written data can be written into the remaining cache block, writing all the metadata of the to-be-written data into the remaining cache block in the first buddy group, and writing all the metadata of the to-be-written data into a metadata block corresponding to a metadata group to which the first buddy group belongs, wherein the cache blocks comprised in each buddy group are successively arranged according to their addresses, wherein the global buddy queue is used for recording buddy groups included in all metadata groups, wherein the metadata is used for describing and organizing a relationship between data blocks, wherein the global buddy queue comprises multiple queues, each of which includes multiple buddy groups, wherein the buddy groups in each queue are arranged in descending order according to the quantities of remaining cache blocks included in the buddy groups, wherein each piece of metadata in a metadata block is stored in a cache block, wherein, after all the metadata of the to-be-written data is written into the remaining cache block in the first buddy group, - a quantity of remaining cache blocks in the first buddy group is updated, - a location of the first buddy group in the global buddy queue is adjusted according to a current quantity of remaining cache blocks in the first buddy group, and - a location of the first buddy group in a buddy queue of the metadata group to which the first buddy group belongs is adjusted. receiving an IO request write command, wherein the IO request write command comprises metadata of to-be-written data; obtaining a buddy group that is currently being processed from a global buddy queue, and using the buddy group as a first buddy group, wherein each buddy group comprises multiple cache blocks in a memory, each buddy group belongs to one metadata group, and one metadata group is corresponding to one metadata block; determining whether the first buddy group has a remaining cache block and whether all metadata of the to-be-written data can be written into the remaining cache block; and when the first buddy group has the remaining cache block and all the metadata of the to-be-written data can be written into the remaining cache block, writing all the metadata of the to-be-written data into the remaining cache block in the first buddy group, and writing all the metadata of the to-be-written data into a metadata block corresponding to a metadata group to which the first buddy group belongs, wherein the cache blocks comprised in each buddy group are successively arranged according to their addresses, wherein the global buddy queue is used for recording buddy groups included in all metadata groups, wherein the metadata is used for describing and organizing a relationship between data blocks, wherein the global buddy queue comprises multiple queues, each of which includes multiple buddy groups, wherein the buddy groups in each queue are arranged in descending order according to the quantities of remaining cache blocks included in the buddy groups, wherein each piece of metadata in a metadata block is stored in a cache block, wherein, after all the metadata of the to-be-written data is written into the remaining cache block in the first buddy group, - a quantity of remaining cache blocks in the first buddy group is updated, - a location of the first buddy group in the global buddy queue is adjusted according to a current quantity of remaining cache blocks in the first buddy group, and - a location of the first buddy group in a buddy queue of the metadata group to which the first buddy group belongs is adjusted. - a quantity of remaining cache blocks in the first buddy group is updated, - a location of the first buddy group in the global buddy queue is adjusted according to a current quantity of remaining cache blocks in the first buddy group, and - a location of the first buddy group in a buddy queue of the metadata group to which the first buddy group belongs is adjusted.