Jump to content

Recommended Posts

Posted

+1 for this question .

 

what i can help from the basic  code, , the cache system is already enabled by default in blesta Configure::set("Caching.on", true) .

 

a sample code like this can work , but not tested .

$cache = Cache::fetchcache('your_plugin_controller_pdt_file', $this->company_id . DS . 'plugins' . DS );

//  if a copy of cache existe
if ($cache) {
  // here you should return the cached file
  return unserialize(base64_decode($cache)); 
 
}
// no cache existe , return output and create cached file
else {
  $pdt_file = $this->view->fetch("your_plugin_controller_pdt_file"); // get the pdt file
  // create cached file if cache system enabled 
  if ( (Configure::get('Caching.on') && is_writable(CACHEDIR)) ) {
   Cache::writecache('your_plugin_controller_pdt_file', base64_encode(serialize($pdt_file)), strtotime( Configure::get('Blesta.cache_length') ) - time(  ), $this->company_id . DS . 'plugins' . DS );
  }
}
Posted

Something like..

// Fetch from cache
$cache = Cache::fetchCache('file_name', $this->company_id . DS . 'directory' . DS);

if ($cache) {
    $data = unserialize(base64_decode($cache));
} else {
    // Fetch the data to store in the cache
    $data = 'my data';

    // Write to cache
    if (Configure::get('Caching.on') && is_writable(CACHEDIR)) {
        try {
            Cache::writeCache(
                'file_name',
                base64_encode(serialize($data)),
                strtotime(Configure::get('Blesta.cache_length')) - time(),
                $this->company_id . DS . 'directory' . DS
            );
        } catch (Exception $e) {
            // Couldn't cache
        }
    }
}

// Use $data
Posted

 

Something like..

// Fetch from cache
$cache = Cache::fetchCache('file_name', $this->company_id . DS . 'directory' . DS);

if ($cache) {
    $data = unserialize(base64_decode($cache));
} else {
    // Fetch the data to store in the cache
    $data = 'my data';

    // Write to cache
    if (Configure::get('Caching.on') && is_writable(CACHEDIR)) {
        try {
            Cache::writeCache(
                'file_name',
                base64_encode(serialize($data)),
                strtotime(Configure::get('Blesta.cache_length')) - time(),
                $this->company_id . DS . 'directory' . DS
            );
        } catch (Exception $e) {
            // Couldn't cache
        }
    }
}

// Use $data

 

So we can set the directory to say cms and it will make /cache/1/cms/ and put the files in there mate like you have with nav?

Posted

Normally the plugin should add the folder in installation or update . Like the support manager .

@tyson , what if we want to cache pdt file instead of calling it every time ? Your example for caching just a data .

 

I believe that's all it is mate, in the nav/ cache files there's a big encryption hash.

Posted

 

Template files can be cached automatically by specifying so, e.g.

class MyController extends AppController {
    public function myPage() {
        $this->startCaching(Configure::get("Blesta.cache_length"));
        ...
    }
}

 

from the controller i see the function render , is caching template file if is set to , but is not doing any thing to fetch the cached file from cache system if the cahce system is set and the file is cached ?

 

this is projected for next releases or there is no attention to do that in the core system .

Posted

The dispatcher fetches cached templates and then displays them. Depending on what you're doing, this may or may not be what you want, as your controller logic will be bypassed.

 

Consider the following scenario:

- Your plugin requires an admin to be logged in, and then displays information only they should see.

- Your plugin caches the template that was shown (as mentioned in post 8) when the admin visits the page.

 

Now anyone that visits the URI that the admin went to will see the cached data. You do not need to be logged in, as the dispatcher will display the content immediately, bypassing your controller and any other logic that may exist to verify the user's authentication. So, if you are showing static data that any public user should see, caching like this will be fine. However, if you are looking to restrict access to the template, then you do not want to cache it in this manner.

Posted

The dispatcher fetches cached templates and then displays them. Depending on what you're doing, this may or may not be what you want, as your controller logic will be bypassed.

 

Consider the following scenario:

- Your plugin requires an admin to be logged in, and then displays information only they should see.

- Your plugin caches the template that was shown (as mentioned in post 8) when the admin visits the page.

 

Now anyone that visits the URI that the admin went to will see the cached data. You do not need to be logged in, as the dispatcher will display the content immediately, bypassing your controller and any other logic that may exist to verify the user's authentication. So, if you are showing static data that any public user should see, caching like this will be fine. However, if you are looking to restrict access to the template, then you do not want to cache it in this manner.

 

How does one remove a file from the cache mate?

Posted

How does one remove a file from the cache mate?

 

If you cached the page as I mentioned in post 8, then you can clear it programmatically via:

class MyController extends AppController {
    public function myPage() {
        $this->clearCache();
        ...
    }
}

If the URI differs from the URI of the page you cached, you can specify the cached URI as the first argument to clearCache in order to remove it from the cache.

Posted

Tested the caching system of pages , it cache it under the root directory of cache (maybe is a bug in multi-company installs, as it should cache them under the directory id of company) .

 

in a multi-languages system , is useless tool, as it cache the whole page output (including head/body) . so when the user has a different language rathar than the admin , he will see the page in the admin's language (a improvement to cache page for every language is a awesmone feature to add ) .

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...