-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Caching and Tests #25
Open
torandi
wants to merge
80
commits into
edruid:master
Choose a base branch
from
torandi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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...