Plugin Directory

Changeset 1263744


Ignore:
Timestamp:
10/12/2015 02:41:11 AM (10 years ago)
Author:
ppohler
Message:

added caching

Location:
rets-rabbit/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • rets-rabbit/trunk/docs/rets_rabbit_for_wordpress_user_guide.md

    r1102919 r1263744  
    33*Author:* Patrick Pohler
    44
    5 *Version:* 1.0.0
     5*Version:* 1.0.6
    66
    77*URL:* <http://retsrabbit.com>
     
    115115- **paginate** (default:true): used w/ the **limit** parameter, setting this to true will generate pagination links for the results
    116116- **num_photos** (default: 1): the max number of photos for each listing. Default is **-1** (all photos) while **0** will display no photos
     117- **cache** (default: false): enable cache
     118- **cache_duration** (default: 4 hrs)
    117119
    118120### Displaying a single listing
     
    127129- **template** (default: 'detail.php'): the template file in the `plugins\retsrabbit\template` directory used to show the detail page for the listing
    128130- **num_photos** (default: -1): the max number of photos for each listing. Default is **-1** (all photos) while **0** will display none
     131- **cache** (default: false): enable cache
     132- **cache_duration** (default: 4 hrs)
     133
    129134
    130135The **detail.php** template can be modified to display the listing details. The listing data will be in an array called **$result**:
  • rets-rabbit/trunk/readme.txt

    r1263706 r1263744  
    44Requires at least: 3.0.1
    55Tested up to: 4.3
    6 Stable tag: 1.0.5
     6Stable tag: 1.0.6
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    103103== Changelog ==
    104104
     105 = 1.0.6 - Add caching options
     106
    105107 = 1.0.4 - Updated for new API changes
    106108
  • rets-rabbit/trunk/retsrabbit.php

    r1263706 r1263744  
    44Plugin URI: http://retsrabbit.com/wordpress
    55Description: Plugin to integrate the real estate cloud service, Rets Rabbit, with Wordpress.
    6 Version: 1.0.5
     6Version: 1.0.6
    77Author: Patrick Pohler
    88Author URI: http://www.anecka.com
  • rets-rabbit/trunk/rr_actions.php

    r1263706 r1263744  
    5252
    5353function retsrabbit_clear_transients($option, $oldvalue, $_newvalue) {
    54     delete_transient('rr-search-query');
    55     delete_transient('retsrabbit-access-code');
    56     delete_transient('rr-metadata');
     54    if($option == "rr-client-id"){
     55        delete_transient('retsrabbit-access-code');
     56        delete_transient('rr-metadata');       
     57    }
    5758}
    5859?>
  • rets-rabbit/trunk/rr_adapter.php

    r1263335 r1263744  
    5353    }
    5454
    55     public function get_listing($mls_id, $num_photos = -1) {
     55    public function get_listing($mls_id, $num_photos = -1, $cache = false, $cache_duration = 4) {
    5656        $client = new Client($this->access_token, true);
    5757        $servers = $client->getServers();
    5858        $server_hash = $servers[0]['server_hash']; //dangerous, need to adjust this
    59         $response = $client->getListing($server_hash, $mls_id);
     59        $response = null;
     60        $query_key = "";
     61
     62        if($cache) {
     63            $key = "$server_hash:$mls_id";
     64            $query_key = hash('sha256', serialize($key));
     65
     66            $response = get_transient($query_key);
     67        }
     68
     69        if($response == null) {
     70            $response = $client->getListing($server_hash, $mls_id);
     71
     72            if($cache) {
     73                set_transient($query_key, $response, $cache_duration * HOUR_IN_SECONDS);
     74            }
     75        }
    6076
    6177        $variables = array();
     
    7490    }
    7591
    76     public function run_search($params, $limit, $num_photos, $orderby = "", $sort_order = "", $sort_option = "") {
     92    public function run_search($params, $limit, $num_photos, $orderby = "", $sort_order = "", $sort_option = "", $cache = false, $cache_duration = 4) {
    7793        $client = new Client($this->access_token, true);
    7894        $servers = $client->getServers();
    7995        $server_hash = $servers[0]['server_hash']; //dangerous, need to adjust this
     96        $response = null;
     97        $query_key = "";
    8098
    8199        $query = $this->_prepare_query($params, $limit, $orderby, $sort_order, $sort_option);
    82         $response = $client->getSearchListings($server_hash, $query);
     100
     101        if($cache) {
     102            $query_key = hash('sha256', $server_hash.serialize($query));
     103
     104            $response = get_transient($query_key);
     105        }
     106
     107        if($response == null) {
     108            $response = $client->getSearchListings($server_hash, $query);
     109
     110            if($cache) {
     111                set_transient($query_key, $response, $cache_duration * HOUR_IN_SECONDS);
     112            }
     113        }
     114
    83115
    84116        $variables = array();
  • rets-rabbit/trunk/rr_shortcodes.php

    r1238274 r1263744  
    1111        $orderby = (isset($atts['orderby']) ? $atts['orderby'] : "");
    1212        $sort_order = (isset($atts['sort_order']) ? $atts['sort_order'] : "");
     13        $cache = (isset($atts['cache']) ? $atts['cache'] : false);
     14        $cache_duration = (isset($atts['cache_duration']) ? $atts['cache_duration'] : 4);
    1315
    1416        $params = json_decode($atts['params'], true);
    1517
    1618        $rr_adapter = new rr_adapter();
    17         $results = $rr_adapter->run_search($params, $limit, $num_photos, $orderby, $sort_order);
     19        $results = $rr_adapter->run_search($params, $limit, $num_photos, $orderby, $sort_order, $cache, $cache_duration);
    1820        //$results = $response->results;
    1921        return $rr_adapter->parse($results, $template, $paginate, $limit);
     
    2527        $template = (isset($atts['template']) ? $atts['template'] : 'detail.php');
    2628        $num_photos = (isset($atts['num_photos']) ? $atts['num_photos'] : -1);
     29        $cache = (isset($atts['cache']) ? $atts['cache'] : false);
     30        $cache_duration = (isset($atts['cache_duration']) ? $atts['cache_duration'] : 4);
    2731
    2832        if(!$mls_id = get_query_var('mls_id'))
     
    3034
    3135        $rr_adapter = new rr_adapter();
    32         $result = $rr_adapter->get_listing($mls_id, $num_photos);
     36        $result = $rr_adapter->get_listing($mls_id, $num_photos, $cache, $cache_duration);
    3337        return $rr_adapter->parse_single($result, $template);
    3438    }
     
    4852        $num_photos = (isset($atts['num_photos']) ? $atts['num_photos'] : 1);
    4953        $paginate = (isset($atts['paginate']) ? $atts['paginate'] === 'true' : true);
     54        $cache = (isset($atts['cache']) ? $atts['cache'] : false);
     55        $cache_duration = (isset($atts['cache_duration']) ? $atts['cache_duration'] : 4);
    5056
    5157        $query_params = get_transient('rr-search-query');
     
    5864        if($params != null && sizeof($params) > 0) {
    5965            $rr_adapter = new rr_adapter();
    60             $results = $rr_adapter->run_search($params, $limit, $num_photos, $orderby, $sort_order, $sort_option);
     66            $results = $rr_adapter->run_search($params, $limit, $num_photos, $orderby, $sort_order, $sort_option, $cache, $cache_duration);
    6167
    6268            return $rr_adapter->parse($results, $template, $paginate, $limit);
  • rets-rabbit/trunk/template/search-form.example.php

    r1263706 r1263744  
    3939        </select>
    4040    </div>
     41    <!--
    4142    <div>
    4243        <Label>MLS number</label>
    4344        <input type="text" name="rets:Matrix_Unique_ID:nocase" value="51209969">
    4445    </div>
     46-->
    4547    <?php
    4648    /*
Note: See TracChangeset for help on using the changeset viewer.