savannah-hackers-public
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Savannah-hackers-public] caching strategies


From: Sylvain Beucler
Subject: Re: [Savannah-hackers-public] caching strategies
Date: Sat, 3 May 2008 22:46:08 +0200
User-agent: Mutt/1.5.17+20080114 (2008-01-14)

Hi,


This looks good :)


For clarity I'd suggest using static methods:

Category::count()
Category::clear()
Category::create($name, ...)

$objCat = Category::getCategoryByID($category_id)
$objCat->name()
...

I think it's similar in J2EE's persistence layer (for example).

-- 
Sylvain


On Sat, May 03, 2008 at 07:51:01PM +0200, Sahid Ferdjaoui wrote:
> Hello
> 
> I have review people with full object.
> 
> exemple with category
> 
> Category::singleton ()->count () # return a number of category
> Category::singleton ()->clear () # clear a category cache in memcached
> Category::singleton ()->create ($name, ...) # create a new category
> 
> $objCatShot = Category::singleton ()->getCategoryByID ($category_id) #
> return CategoryShot object
> $objCatShot->name () #return the name of category
> $objCatShot->count () # return a number of job in this category
> $objCatShot->del () # for remove this category
> $objCatShot->edit ($name) # for edit this category
> 
> for Job, now there is Job and JobShot classes
> $objJobShot = $objCatShot->Job () # return a JobShot object of this
> CategoryShot object
> or
> $objJobShot = Job::singleton ($category_id) # return a JobShot object
> of this category id
> $objJobShot->edit ($title, ...) # for edit this job
> $objJobShot->del () # for remove this job
> ...
> 
> 
> i have rewrite two functions for exemple (people/general.php):
> 
> function people_get_category_name($category_id)
> {
>   $objCatShot = Category::singleton ()->getCategoryById ($category_id);
>   if (!is_object ($objCatShot))
>     {
>       return 'Invalid ID';
>     }
>   return $objCatShot->name ();
> }
> 
> function people_show_category_table()
> {
> 
>   #show a list of categories in a table
>   #provide links to drill into a detail page that shows these categories
> 
>   $title_arr=array();
>   $title_arr[]=_("Category");
> 
>   $return = '';
>   $return .= html_build_list_table_top ($title_arr);
> 
>   if (Category::singleton ()->count () < 1)
>     {
>       $return .= '<tr><td><h2>'._("No Categories Found").'</h2></td></tr>';
>     }
>   else
>     {
>       foreach (Category::singleton ()->fetch () as $i => $objCatShot)
>         {
>           $return .= '<tr class="'. utils_get_alt_row_color ($i)
> .'"><td><a href="'.$GLOBALS['sys_home'].'people/?category_id='.
>             $objCatShot->ID ().'">'.
>             $objCatShot->name ().'</a> ('. $objCatShot->count 
> ().')</td></tr>';
>         }
>     }
>   $return .= '</table>';
>   return $return;
> }
> 
> it's OK, i continue ?
> 
> 
> On Sat, May 3, 2008 at 2:46 PM, Sylvain Beucler <address@hidden> wrote:
> > Hi,
> >
> >  I dislike solution number 1 too :)
> >
> >  But clearing the cache in add_job is not enough :/ Other functions can
> >  alter the cached data: when a user is renamed, when a group changes
> >  its group type or its name, when a job is removed, when a user is
> >  deleted, etc.
> >
> >  I liked the idea from http://www.danga.com/memcached/ where the cache
> >  was always accurate (using getter+setter). I don't know how applicable
> >  this is for Savane.
> >
> >  --
> >  Sylvain
> >
> >
> >
> >
> >  On Wed, Apr 30, 2008 at 10:36:22PM +0200, Sahid Ferdjaoui wrote:
> >  > ok,
> >  >
> >  > two solutions :
> >  >
> >  > - the "people category" data's doesn't need be always up to date.
> >  > - i add a function for clear cache in add_job
> >  >
> >  > i think the seconds methode is better :)
> >  >
> >  >
> >  >
> >  > On Wed, Apr 30, 2008 at 10:14 PM, Sylvain Beucler <address@hidden> wrote:
> >  > > Hi,
> >  > >
> >  > >  This is a good start.
> >  > >
> >  > >  One issue is that the cache is not invalidated when `people_job` is
> >  > >  changed, which means Savannah can return inconsistent results for 5
> >  > >  minutes.
> >  > >
> >  > >  P.S.: please keep address@hidden in Cc: so that other
> >  > >  people in the team can see what's going on :)
> >  > >
> >  > >  --
> >  > >  Sylvain
> >  > >
> >  > >
> >  > >
> >  > >
> >  > >  On Wed, Apr 30, 2008 at 09:24:06PM +0200, Sahid Ferdjaoui wrote:
> >  > >  > Hello Sylvain
> >  > >  >
> >  > >  > i have developed Cache abstract class
> >  > >  > http://pastebin.funraill.org/ee9d39ff874d1adeca7653b9630e7af7/
> >  > >  >
> >  > >  > for the database, I think it, add two new functions :
> >  > >  > db_cache_fetch (); and db_cache_row ();
> >  > >  > view source : 
> > http://pastebin.funraill.org/73497bfce7ede4fa0d0fb5700de7e506/
> >  > >  >
> >  > >  > i have review people_show_category_table () with new function
> >  > >  > http://pastebin.funraill.org/96c162c4fd92eca6cb718c366c216c8c/
> >  > >  >
> >  > >  > I wait your suggestion sylvain :)
> >  > >  >
> >  > >  > also i have add new memched debug's in init.php
> >  > >  >
> >  > >  > (sorry for my bad english)
> >  > >  >
> >  > >  > On Tue, Apr 29, 2008 at 7:40 PM, Sylvain Beucler <address@hidden> 
> > wrote:
> >  > >  > > Hi,
> >  > >  > >
> >  > >  > >  Reviewing /people is a good idea; we'll see and discuss how you
> >  > >  > >  envision introducing memcache support in the code.
> >  > >  > >
> >  > >  > >  (A priori I think that memcache'd data need to be properly
> >  > >  > >  encapsulated (getter+setter) to avoid differences between MySQL 
> > and
> >  > >  > >  the memcache, and update the memcache whenever the data changes.)
> >  > >  > >
> >  > >  > >
> >  > >  > >  For the most often used queries: I enabled 
> > $sys_debug_sqlprofiler (as
> >  > >  > >  seen in include/database.php) at Savannah. The results are 
> > viewable
> >  > >  > >  through https://savannah.gnu.org/xcache/?type=1 (sort by 'Hits').
> >  > >  > >
> >  > >  > >  --
> >  > >  > >  Sylvain
> >  > >  > >
> >  > >  > >
> >  > >  > >
> >  > >  > >  On Tue, Apr 29, 2008 at 06:42:57PM +0200, Sahid Ferdjaoui wrote:
> >  > >  > >  > Hello Sylvain
> >  > >  > >  >
> >  > >  > >  > OK, I can try reduce MySQL load
> >  > >  > >  >
> >  > >  > >  > for begin, i try reviewing "/people", OK ?
> >  > >  > >  > or you can tell me, what are the primaries modules load MySQL.
> >  > >  > >  >
> >  > >  > >  >
> >  > >  > >  > On Tue, Apr 29, 2008 at 12:29 AM, Sahid Ferdjaoui 
> > <address@hidden> wrote:
> >  > >  > >  > > OK Sylvain thank,
> >  > >  > >  > >
> >  > >  > >  > >  I try to install savannah and i try understand the actualy 
> > code :)
> >  > >  > >  > >
> >  > >  > >  > >  good night
> >  > >  > >  > >
> >  > >  > >  > >
> >  > >  > >  > >
> >  > >  > >  > >
> >  > >  > >  > >
> >  > >  > >  > >
> >  > >  > >  > >  On Mon, Apr 28, 2008 at 8:30 PM, Sylvain Beucler 
> > <address@hidden> wrote:
> >  > >  > >  > >  > Hi,
> >  > >  > >  > >  >
> >  > >  > >  > >  >  Thanks for contributing to GNU :)
> >  > >  > >  > >  >
> >  > >  > >  > >  >  We've assembled a list of "help needed" tasks at:
> >  > >  > >  > >  >  http://savannah.gnu.org/maintenance/SavaneTasks
> >  > >  > >  > >  >
> >  > >  > >  > >  >  Can you read it and tell us what you are interested in?
> >  > >  > >  > >  >
> >  > >  > >  > >  >
> >  > >  > >  > >  >  Since you already used memcached, here's another idea 
> > just for you:
> >  > >  > >  > >  >  we'd like Savane to use memcached to reduce the MySQL 
> > load; the
> >  > >  > >  > >  >  criticil points are (IMHO):
> >  > >  > >  > >  >  - the code is not well encapsulated
> >  > >  > >  > >  >  - a lot of queries use JOINs, which I believe won't be 
> > easy to replace
> >  > >  > >  > >  >   with similar memcached calls
> >  > >  > >  > >  >  Suggestions/code appreciated ;)
> >  > >  > >  > >  >
> >  > >  > >  > >  >  Hear from you soon,
> >  > >  > >  > >  >
> >  > >  > >  > >  >  --
> >  > >  > >  > >  >  Sylvain
> >  > >  > >  > >  >
> >  > >  > >  > >  >  > Subject: [gnu.org #360924] PHP developer for savanah
> >  > >  > >  > >  >  > From: Sahid Ferdjaoui via RT <address@hidden>
> >  > >  > >  > >  >  > Date: Sun, 27 Apr 2008 08:21:26 -0400
> >  > >  > >  > >  >  > Hello,
> >  > >  > >  > >  >  >
> >  > >  > >  > >  >  > I'm french, i'm 23 years, i'm passionte by open 
> > sources projects in
> >  > >  > >  > >  >  > particulary gnu project.
> >  > >  > >  > >  >  > Currently i'm computer programmer for comunity web 
> > site, developed
> >  > >  > >  > >  >  > with PHP, Apache, MySQL and Memcached.
> >  > >  > >  > >  >  > i have developed for this web site, a MySQL and 
> > Memcached abstracts
> >  > >  > >  > >  >  > classes,  a secure payment's API with GUI's admin, 
> > SOAP and REST web
> >  > >  > >  > >  >  > services.
> >  > >  > >  > >  >  >
> >  > >  > >  > >  >  > if you want my CV contact me.
> >  > >  > >  > >  >  > you can see my french blog http://sahid.funraill.org
> >  > >  > >  > >  >  >
> >  > >  > >  > >  >  > Thanks




reply via email to

[Prev in Thread] Current Thread [Next in Thread]