Software-defined networks (SDNs) provide flexibility for developing new network protocols and policies in real networks. The SDN controller translates network policies into specific rules in the flow tables [which are usually implemented using ternary content addressable memory (TCAM)] of each network switch. However, due to the limitation of TCAM (e.g., high power consumption and high heat generation), the flow tables cannot scale beyond a few hundred entries. Hence, the switches usually reactively cache rules (i.e., installing rules on demand). However, the reactively caching rules causes packet delay and large buffers, when cache misses happen. To improve the performance, in this paper, we propose a rule partition and allocation algorithm to distribute the rules across network switches. Our algorithm not only is applicable to small TCAM switch scenario but also guarantees semantically invariant (i.e., the global action of the network is unchanged).