If  in your magento system,`magento cron jobs are working properly` then 
you define `a cronjob` which ***fire on midnight and clear cache***.

    <crontab>
    	<jobs>
    		<clean_cache_midnight><!-- identifier -->
    			 <schedule>
    			 	 <cron_expr>0 1 * * *</cron_expr> <!-- run cronjob on midnight -->
    			 </schedule>
    			<run>
    				<model>MyModule_Model_Group_Class_Name::functionName</model>
    			</run>
    		</clean_cache_midnight>
    	</jobs>
    </crontab>

And class is

    <?php
    class [ModuleNameSpace]_[ModuleName]_Model_Mycron
    {
    	public function functionName(){
    		
    	 /**
         * Flush all magento cache
         */
    	 Mage::app()->cleanCache();
    	}
    }

Full module:
------------

create `config.xml` at  ***app/code/community/Amit/Cleancache/etc/***


    <?xml version="1.0" encoding="utf-8"?>
    <config>
    <modules>
        <Amit_Cleancache>
            <version>1.0.0</version>
        </Amit_Cleancache>
    </modules>
    	<global>
    		<models>
    			<cleancache>
    				<class>Amit_Cleancache_Model</class>
    			<cleancache>
    		<models>
    	</global>
    	<crontab>
    		<jobs>
    			<clean_cache_midnight><!-- identifier -->
    				 <schedule>
    				 	 <cron_expr>0 1 * * *</cron_expr> <!-- runign cronjob on midnight -->
    				 </schedule>
    				<run>
    					<model>cleancache/Fire::fireCacheonMidnight</model>
    				</run>
    			</clean_cache_midnight>
    		</jobs>
    	</crontab>
    </config>

**File2:** create  `Fire.php`  at ***app/code/community/Amit/Cleancache/Model/***


**code:**

    <?php
    class Amit_Cleancache_Model_Fire
    {
    	public function fireCacheonMidnight(){
    		
    	 /**
         * Flush all magento cache
         */
    	 Mage::app()->cleanCache();
    	}
    }
**File3:** module config file ***Amit_Cleancache.xml*** at ***app/etc/modules/***

    <?xml version="1.0" encoding="utf-8"?>
    <config>
        <modules>
            <Amit_Cleancache>
                <active>true</active>
    			<codePool>community</codePool>
            </Amit_Cleancache>
        </modules>
    </config>