The resonance frequency of an optical whispering gallery mode (WGM) microcavity is extremely important in its various applications. Many efforts have been made to fine tune this parameter. Here, we report the design and implementation of a function resonance tuner of an optical microcavity with resolution about 650 kHz (7 pm @ 1450 nm band), 20% of the optical WGM linewidth. A piezoelectric nano-positioner is used to mechanically compress the microsphere in its axial direction. The ultrafine frequency tuning is achieved benefitting from the much less changes in the axial direction than equatorial semiaxes of the microsphere and the sub-nanometer resolution of the nano-positioner. The tuning of the resonance can be made to an arbitrary function, dynamically, with near perfect accuracy. We have demonstrated the periodically tuning of resonance in the sine and sigmoid function respectively, both with over 99% fitting accuracy. This work expands the application of microresonators greatly, especially microspheres with ultrahigh quality factor, in multi-mode coupling system or time-floquet system.