| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Conflicts: BasicObject.php
static in base class does not by itself use late static binding, only if the derived class declared the same variable. Thus the from_field cache would collide if two tables had the same column name.
For instance:
$a = Event::from_id(1);
$b = Row::from_id(1);
var_dump($a);
var_dump($b);
Since both tables use "id" the results would collide and show up as the same instance.
The correct order is expected, real
Eg. $foo->Bar(array('baz' => 'bar'))
Undo of commit e8c7537 "Invalid" names after : in column names should be accepted, so that one can construct several where clauses on the same column.
Conflicts: BasicObject.php
After this patch, it only deletes the keys used for structure cache. This is important, because I have other caches in memcache that I want to keep, even when I run migrations that alter db structure.
And a script to install phpunit
|
Sorry about the big pull request, but it's hard to separate (for example: a lot of the tests test caching behaviour, and that the normal behaviour works with and without caching). |
Sorry, something went wrong.
Allows multipe BO on the same memcache
|
Some more commits where added; nothing big. Most important is the addition of prefix to memcache structure cache, allowing multiple BO's to run in parallell on the same memcache instance. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Caching
Adds two kinds of caching, which speeds up performance a lot.
All caching are off by until turned on by BasicObject::enable_cache() or BasicObject::enable_structure_cache($mc)
Structure Cache
Caches all BO structure queries (Foreign key, primary key, table column names etc) in memcached.
This cache gives the highest performance boost, but BasicObject::clear_structure_cache($mc) must manually be called changes to the database structure have been made. I recommend using a migration-like system (for example torandi/php-migrations with a post_migration-hook where one can trigger the cache clean.
Query Caching
Caches query result, but only inside a single request. This still gives some performance boost, since one often execute the same query multiple times in a page view (ex:
forum, look up user from user id, multiple posts from same user, so the user is looked up multiple times).
This cache is only per request, but the query cache for ALL BasicObjects are reset when ANY BasicObject in commited, this is due to the relations and dependencies between models can be quite complex.
A warning: If your code have some manually updates of the database you will have to manually trigger BasicObject::invalidate_cache().
Example:
$foo = Foo::from_id(1);
$db->query("UPDATE FOO set baz='bar' where id=1;")
// Foo::from_id(1) still returns old value of baz, since BO doesn't know the value have changed
Tests
Add a structure for tests, and some tests (not remotely close to full coverage).
Tests are run with ./tests.sh
Tests depend on PHPUnit, which can be installed with ./install_phpunit.sh
tests folder includes Blueprint.php, which is a class written for this that allows you to create blueprints for test objects, see tests/blueprints/README.md
Also: Maybe I should put the text about caching in the README...