Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. def authorSearch(author)
  2. books = []
  3. complex_entity_key = "#{author}"
  4.  
  5. isbns_books = @Remote_cache.get "bks_#{author}"
  6.  
  7. if isbns_books
  8. isbns_books.split(',').each do |isbn|
  9. version = @Remote_cache.get "v_#{isbn}"
  10. if version
  11. complex_entity_key += "_#{isbn}_#{version}"
  12. else
  13. complex_entity_key += "_#{isbn}_1"
  14. end
  15. end
  16.  
  17. str_books = @Remote_cache.get complex_entity_key
  18. if str_books
  19. str_books.split(';').each {|book| books.insert(-1,BookInStock.from_cache(book))}
  20. else
  21. books = @database.authorSearch author
  22. isbns = ""
  23. str_books = ""
  24. complex_entity_key = "#{author}"
  25. books.each do |book|
  26. isbns += "#{book.isbn},"
  27. str_books += "#{book.to_cache};"
  28. version = @Remote_cache.get "v_#{book.isbn}"
  29. if version
  30. complex_entity_key += "_#{book.isbn}_#{version}"
  31. else
  32. complex_entity_key += "_#{book.isbn}_1"
  33. end
  34. end
  35. if books.size>=1
  36. @Remote_cache.set "bks_#{author}", isbns[0,isbns.size-1]
  37. @Remote_cache.set complex_entity_key, str_books[0,str_books.size-1]
  38. end
  39. end
  40. else
  41. books = @database.authorSearch author
  42. isbns = ""
  43. str_books = ""
  44. books.each do |book|
  45. isbns += "#{book.isbn},"
  46. str_books += "#{book.to_cache};"
  47. version = @Remote_cache.get "v_#{book.isbn}"
  48. if version
  49. complex_entity_key += "_#{book.isbn}_#{version}"
  50. else
  51. complex_entity_key += "_#{book.isbn}_1"
  52. end
  53. end
  54.  
  55. if books.size>=1
  56. @Remote_cache.set "bks_#{author}", isbns[0,isbns.size-1]
  57. @Remote_cache.set complex_entity_key, str_books[0,str_books.size-1]
  58. end
  59. end
  60. books
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement