| 458 | self.assertEqual(cache.get(key), value) |
| 459 | |
| 460 | def test_cache_read_for_model_instance(self): |
| 461 | class="cm"># Don't want fields with callable as default to be called on cache read |
| 462 | expensive_calculation.num_runs = 0 |
| 463 | Poll.objects.all().delete() |
| 464 | my_poll = Poll.objects.create(question=class="st">"Well?") |
| 465 | self.assertEqual(Poll.objects.count(), 1) |
| 466 | pub_date = my_poll.pub_date |
| 467 | cache.set(class="st">"question", my_poll) |
| 468 | cached_poll = cache.get(class="st">"question") |
| 469 | self.assertEqual(cached_poll.pub_date, pub_date) |
| 470 | class="cm"># We only want the default expensive calculation run once |
| 471 | self.assertEqual(expensive_calculation.num_runs, 1) |
| 472 | |
| 473 | def test_cache_write_for_model_instance_with_deferred(self): |
| 474 | class="cm"># Don't want fields with callable as default to be called on cache |