Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 663569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:30:14+00:00 2026-05-13T23:30:14+00:00

Right now I’m trying to create my own tiny MVC (just for practice and

  • 0

Right now I’m trying to create my own tiny MVC (just for practice and for understanding MVC pattern details). I’d like to cache parts of pages (dropdowns, lists etc.) and I don’t know what is the best way to organize it.

Let’s imagine that I have PostsController with method getPostDetailsShortly($post_id).
This method could look like this…

public function getPostDetailsShortly($post_id) {

  if (!$post_id) return false;
  $content = $this->memcache->get("post" . $post_id); //Trying to get post details HTML from memcache

  if (!$content) { //Not fount in memcache

    $model = new PostsModel();
    $data = $model->getPostDetailsShortly($post_id);

    $this->view->assign('data', $data);

    ob_start();
    $this->view->render();
    $content = ob_get_contents(); //Getting view output into variable
    ob_end_clean();

    $this->memcache->set('post' . $post_id, $content, 1000); //Writing variable to memcache

  }

  return $content;

}

Now I should make this controller method be available from Views. Because I will use it inside of other pages, for example, for building related posts list.

What is the best practice of doing it? Maybe I’m wrong and there are some better methods to organize caching parts of pages?

PS:Sorry for my English, but I hope it is clear.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:30:15+00:00Added an answer on May 13, 2026 at 11:30 pm

    The idea behind MVC for those who may be reading this who don’t know, is to separate the MODEL, VIEW, and CONTROLLER architecture of the site. I am most familiar with CakePHP MVC framework. So this answer will be based on my knowledge of MVC as it pertains to CakePHP.

    Since the information you are providing needs to be provided to the view, I would suggest building it as an HTML helper. A Helper is designed to provide reusable code to the view. The Controller is the implementation of the logic behind the code (what to do with the data coming from the forms on the view, what views to call, asking the model for data, etc.).

    Looking over the question you are speaking about caching these items. I think it is a good thing if you anticipate getting large amounts of traffic, but not really necessary otherwise. Having said that, it seems the question is more about the architecture than the caching. The current architecture seems sound, but I would move the functionality into a “component” which is accessible from all Controllers. This will allow you to call it from any controller where you need it, without having to call a specific controller every time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now, I've just some code which fetches the picture from the URL directly.
Right now I came across the Observer/Observable pattern where I have my Observable notify
Right now the label is on top of the text box. I would like
Right now, Textmate uses .erb for this, which means it treats it like a
Right now my ant task looks like. <javadoc sourcepath=${source} destdir=${doc}> <link href=http://java.sun.com/j2se/1.5.0/docs/api/ /> </javadoc>
Right now I'm doing something like this: RewriteRule ^/?logout(/)?$ logout.php RewriteRule ^/?config(/)?$ config.php I
Right now, I have code that looks something like this: Private Sub ShowReport(ByVal reportName
Right now, I have an enum like this: public enum ReferenceType { Language =
Right now I am trying to research on how stable Spring release are right
Right now im using css to create an onclick image change. The problem is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.