AbstractCache.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * OpenWeatherMap-PHP-API — A php api to parse weather data from http://www.OpenWeatherMap.org .
  4. *
  5. * @license MIT
  6. *
  7. * Please see the LICENSE file distributed with this source code for further
  8. * information regarding copyright and licensing.
  9. *
  10. * Please visit the following links to read about the usage policies and the license of
  11. * OpenWeatherMap before using this class:
  12. *
  13. * @see http://www.OpenWeatherMap.org
  14. * @see http://www.OpenWeatherMap.org/terms
  15. * @see http://openweathermap.org/appid
  16. */
  17. namespace Cmfcmf\OpenWeatherMap;
  18. /**
  19. * Abstract cache class to be overwritten by custom cache implementations.
  20. */
  21. abstract class AbstractCache
  22. {
  23. /**
  24. * @var int $seconds Cache time in seconds.
  25. */
  26. protected $seconds;
  27. /**
  28. * Checks whether a cached weather data is available.
  29. *
  30. * @param string $url The unique url of the cached content.
  31. *
  32. * @return bool False if no cached information is available, otherwise true.
  33. *
  34. * You need to check if a cached result is outdated here. Return false in that case.
  35. */
  36. abstract public function isCached($url);
  37. /**
  38. * Returns cached weather data.
  39. *
  40. * @param string $url The unique url of the cached content.
  41. *
  42. * @return string|bool The cached data if it exists, false otherwise.
  43. */
  44. abstract public function getCached($url);
  45. /**
  46. * Saves cached weather data.
  47. *
  48. * @param string $url The unique url of the cached content.
  49. * @param string $content The weather data to cache.
  50. *
  51. * @return bool True on success, false on failure.
  52. */
  53. abstract public function setCached($url, $content);
  54. /**
  55. * Set after how much seconds the cache shall expire.
  56. *
  57. * @param int $seconds
  58. */
  59. public function setSeconds($seconds)
  60. {
  61. $this->seconds = $seconds;
  62. }
  63. }