I'm new to add-on development and have built a simple plugin to return an integer of the number of entries a user has posted in a certain channel.

I want to call this plugin a few times in an EE template. With the way it is set up now, does that mean the plugin will query the DB every time I call it?

If so, is there a better way to write this?

Thanks,

```
        <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

            $plugin_info = array(
                'pi_name'       => 'Camper Count',
                'pi_version'    => '1.0',
                'pi_author'     => '',
                'pi_author_url' => '',
                'pi_description'=> 'Count the number of campers a logged in user has and return an integer.',
                'pi_usage'      => Camper_count::usage()
            );

            class Camper_count {

                /**
                 * Specific Vars for Channel and Status
                 * Since this will only be used to export from one channel
                 *
                 * @var array
                 * @access protected
                 **/
                protected $channel_id = 20; // The ID for the 'Campers' Channel
                protected $channel_entry_status = 'open';

                /**
                 * Return Data
                 **/
                public $return_data;

                /**
                 * Constructor
                 */
                public function __construct()
                {
                    $this->EE =& get_instance();

                    // Make the Query
                    $this->EE->db->from('exp_channel_titles');
                    $this->EE->db->where('channel_id', $this->channel_id);
                    $this->EE->db->where('status', $this->channel_entry_status);
                    $this->EE->db->where('author_id', $this->EE->session->userdata('member_id'));
                    //$this->EE->db->where('exp_channel_titles.entry_date >=', strtotime($config['date_filter_start']));
                    //$this->EE->db->where('exp_channel_titles.entry_date <=', strtotime($config['date_filter_end']));
                    $count = $this->EE->db->count_all_results();

                    /*
                     * Since the user will be registering a new camper, incrememnt the camper count up by 1.
                     * If there are no campers returned, then this is their first camper. Return 1.
                     */
                    if($count > 0)
                    {
                        $this->return_data = $count + 1;
                    }
                    else
                    {
                        $this->return_data = 1;
                    }
                }

                // ----------------------------------------------------------------

                /**
                 * Plugin Usage
                 */
                public static function usage()
                {
                    ob_start();
            ?>

            Returns an integer of the number of campers a logged in user has. {exp:camper_count}
            <?php
                    $buffer = ob_get_contents();
                    ob_end_clean();
                    return $buffer;
                }
            }

            /* End of file pi.camper_count.php */
            /* Location: /system/expressionengine/third_party/camper_count/pi.camper_count.php */

```