Thinkphp clears cache

Source: Internet
Author: User
Dedecms has the cache clearing function, so I tried to study it. The result shows that I am in the fog. hi .... I checked the results on the Internet and wrote a Cache clearing function according to my website...

Dedecms has the cache clearing function, so I tried to study it. The result shows that I am in the fog. hi .... as a result, I checked it online and wrote a Cache clearing function based on my website.

Tp execution code:

  1. // Obtain the absolute path of the desired directory and Directory
  2. Public function cache (){
  3. /// The front-end submits the request in ajax get mode. here we will first judge
  4. If ($ _ POST ['type']) {
  5. // Obtain the passed value
  6. $ Type = $ _ POST ['type'];
  7. // Cut the passed value. I have "-" cut
  8. $ Name = explode ('-', $ type );
  9. // Obtain the number of slices to facilitate the following cycle
  10. $ Count = count ($ name );
  11. // Call the above method cyclically
  12. For ($ I = 0; $ I <$ count; $ I ++ ){
  13. // Obtain the absolute path of the object
  14. $ Abs_dir = dirname (_ FILE __))));
  15. // Combined path
  16. $ Pa = $ abs_dir. '\ index \ Runtime \\';
  17. $ Runtime = $ abs_dir. '\ index \ Runtime \~ Runtime. php ';
  18. If (file_exists ($ runtime) // checks whether the object exists.
  19. {
  20. Unlink ($ runtime); // delete a file
  21. }
  22. // Call the method to delete all objects in a folder
  23. $ This-> rmFile ($ pa, $ name [$ I]);
  24. }
  25. // Provides prompt information
  26. $ This-> ajaxReturn (1, 'cleared successfully', 1 );
  27. } Else {
  28. $ This-> display ();
  29. }
  30. }
  31. Public function rmFile ($ path, $ fileName) {// delete the execution method
  32. // Remove spaces
  33. $ Path = preg_replace ('/(\/) {2, }|{\\\}{ 1,}/', '/', $ path );
  34. // Obtain The Complete Directory
  35. $ Path. = $ fileName;
  36. // Determine whether the file is a file directory
  37. If (is_dir ($ path )){
  38. // Open the file
  39. If ($ dh = opendir ($ path )){
  40. // Retrieve the file directory name
  41. While ($ file = readdir ($ dh ))! = False ){
  42. // Delete one by one
  43. Unlink ($ path. '\'. $ file );
  44. }
  45. // Close the file
  46. Closedir ($ dh );
  47. }
  48. }
  49. }

Tp: front-end code (a little crude)

  1.  
  2. -->

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.