All optically driven memory device for terahertz waves